本文整理汇总了Python中django.db.backends.base.schema.BaseDatabaseSchemaEditor方法的典型用法代码示例。如果您正苦于以下问题:Python schema.BaseDatabaseSchemaEditor方法的具体用法?Python schema.BaseDatabaseSchemaEditor怎么用?Python schema.BaseDatabaseSchemaEditor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.backends.base.schema
的用法示例。
在下文中一共展示了schema.BaseDatabaseSchemaEditor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_migrate_syncdb_deferred_sql_executed_with_schemaeditor
# 需要导入模块: from django.db.backends.base import schema [as 别名]
# 或者: from django.db.backends.base.schema import BaseDatabaseSchemaEditor [as 别名]
def test_migrate_syncdb_deferred_sql_executed_with_schemaeditor(self):
"""
For an app without migrations, editor.execute() is used for executing
the syncdb deferred SQL.
"""
stdout = io.StringIO()
with mock.patch.object(BaseDatabaseSchemaEditor, 'execute') as execute:
call_command('migrate', run_syncdb=True, verbosity=1, stdout=stdout, no_color=True)
create_table_count = len([call for call in execute.mock_calls if 'CREATE TABLE' in str(call)])
self.assertEqual(create_table_count, 2)
# There's at least one deferred SQL for creating the foreign key
# index.
self.assertGreater(len(execute.mock_calls), 2)
stdout = stdout.getvalue()
self.assertIn('Synchronize unmigrated apps: unmigrated_app_syncdb', stdout)
self.assertIn('Creating tables...', stdout)
table_name = truncate_name('unmigrated_app_syncdb_classroom', connection.ops.max_name_length())
self.assertIn('Creating table %s' % table_name, stdout)
示例2: setup_projections_table
# 需要导入模块: from django.db.backends.base import schema [as 别名]
# 或者: from django.db.backends.base.schema import BaseDatabaseSchemaEditor [as 别名]
def setup_projections_table(self, process):
from django.db import connections
with connections["default"].schema_editor() as schema_editor:
assert isinstance(schema_editor, BaseDatabaseSchemaEditor)
try:
schema_editor.delete_model(self.projection_record_class)
except django.db.utils.ProgrammingError:
pass
with connections["default"].schema_editor() as schema_editor:
assert isinstance(schema_editor, BaseDatabaseSchemaEditor)
schema_editor.create_model(self.projection_record_class)
示例3: database_forwards
# 需要导入模块: from django.db.backends.base import schema [as 别名]
# 或者: from django.db.backends.base.schema import BaseDatabaseSchemaEditor [as 别名]
def database_forwards(self, app_label, schema_editor: BaseDatabaseSchemaEditor, from_state, to_state: ProjectState):
to_model = to_state.apps.get_model(app_label, self.model_name)
meta = to_model._meta
to_field = meta.get_field(self.name)
if to_field.default != NOT_PROVIDED:
table_name = schema_editor.quote_name(meta.db_table)
column = schema_editor.quote_name(to_field.column)
default = schema_editor.quote_value(to_field.default)
schema_editor.execute("ALTER TABLE {} ALTER COLUMN {} SET DEFAULT {}".format(table_name, column, default))
示例4: database_backwards
# 需要导入模块: from django.db.backends.base import schema [as 别名]
# 或者: from django.db.backends.base.schema import BaseDatabaseSchemaEditor [as 别名]
def database_backwards(self, app_label, schema_editor: BaseDatabaseSchemaEditor, from_state, to_state):
self.database_forwards(app_label, schema_editor, from_state, to_state)
示例5: test_migrate_syncdb_deferred_sql_executed_with_schemaeditor
# 需要导入模块: from django.db.backends.base import schema [as 别名]
# 或者: from django.db.backends.base.schema import BaseDatabaseSchemaEditor [as 别名]
def test_migrate_syncdb_deferred_sql_executed_with_schemaeditor(self):
"""
For an app without migrations, editor.execute() is used for executing
the syncdb deferred SQL.
"""
with mock.patch.object(BaseDatabaseSchemaEditor, 'execute') as execute:
call_command('migrate', run_syncdb=True, verbosity=0)
create_table_count = len([call for call in execute.mock_calls if 'CREATE TABLE' in str(call)])
self.assertEqual(create_table_count, 2)
# There's at least one deferred SQL for creating the foreign key
# index.
self.assertGreater(len(execute.mock_calls), 2)
示例6: test_migrate_syncdb_app_label
# 需要导入模块: from django.db.backends.base import schema [as 别名]
# 或者: from django.db.backends.base.schema import BaseDatabaseSchemaEditor [as 别名]
def test_migrate_syncdb_app_label(self):
"""
Running migrate --run-syncdb with an app_label only creates tables for
the specified app.
"""
stdout = io.StringIO()
with mock.patch.object(BaseDatabaseSchemaEditor, 'execute') as execute:
call_command('migrate', 'unmigrated_app_syncdb', run_syncdb=True, stdout=stdout)
create_table_count = len([call for call in execute.mock_calls if 'CREATE TABLE' in str(call)])
self.assertEqual(create_table_count, 2)
self.assertGreater(len(execute.mock_calls), 2)
self.assertIn('Synchronize unmigrated app: unmigrated_app_syncdb', stdout.getvalue())