当前位置: 首页>>代码示例>>Python>>正文


Python schema.BaseDatabaseSchemaEditor方法代码示例

本文整理汇总了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) 
开发者ID:nesdis,项目名称:djongo,代码行数:20,代码来源:test_commands.py

示例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) 
开发者ID:johnbywater,项目名称:eventsourcing,代码行数:15,代码来源:test_process_with_django.py

示例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)) 
开发者ID:zaihui,项目名称:hutils,代码行数:11,代码来源:migrations.py

示例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) 
开发者ID:zaihui,项目名称:hutils,代码行数:4,代码来源:migrations.py

示例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) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:14,代码来源:test_commands.py

示例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()) 
开发者ID:nesdis,项目名称:djongo,代码行数:14,代码来源:test_commands.py


注:本文中的django.db.backends.base.schema.BaseDatabaseSchemaEditor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。