本文整理匯總了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())