本文整理匯總了Python中django.db.migrations.questioner.MigrationQuestioner方法的典型用法代碼示例。如果您正苦於以下問題:Python questioner.MigrationQuestioner方法的具體用法?Python questioner.MigrationQuestioner怎麽用?Python questioner.MigrationQuestioner使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.db.migrations.questioner
的用法示例。
在下文中一共展示了questioner.MigrationQuestioner方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_trim_apps
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def test_trim_apps(self):
"""
Trim does not remove dependencies but does remove unwanted apps.
"""
# Use project state to make a new migration change set
before = self.make_project_state([])
after = self.make_project_state([self.author_empty, self.other_pony, self.other_stable, self.third_thing])
autodetector = MigrationAutodetector(before, after, MigrationQuestioner({"ask_initial": True}))
changes = autodetector._detect_changes()
# Run through arrange_for_graph
graph = MigrationGraph()
changes = autodetector.arrange_for_graph(changes, graph)
changes["testapp"][0].dependencies.append(("otherapp", "0001_initial"))
changes = autodetector._trim_to_apps(changes, {"testapp"})
# Make sure there's the right set of migrations
self.assertEqual(changes["testapp"][0].name, "0001_initial")
self.assertEqual(changes["otherapp"][0].name, "0001_initial")
self.assertNotIn("thirdapp", changes)
示例2: test_rename_field_and_foo_together
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def test_rename_field_and_foo_together(self):
"""
Removed fields will be removed after updating index/unique_together.
"""
changes = self.get_changes(
[self.author_empty, self.book_foo_together_3],
[self.author_empty, self.book_foo_together_4],
MigrationQuestioner({"ask_rename": True}),
)
# Right number/type of migrations?
self.assertNumberMigrations(changes, "otherapp", 1)
self.assertOperationTypes(changes, "otherapp", 0, ["RenameField", "AlterUniqueTogether", "AlterIndexTogether"])
self.assertOperationAttributes(changes, "otherapp", 0, 1, name="book", unique_together={
("title", "newfield2")
})
self.assertOperationAttributes(changes, "otherapp", 0, 2, name="book", index_together={("title", "newfield2")})
示例3: test_rename_model_with_renamed_rel_field
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def test_rename_model_with_renamed_rel_field(self):
"""
Tests autodetection of renamed models while simultaneously renaming one
of the fields that relate to the renamed model.
"""
changes = self.get_changes(
[self.author_with_book, self.book],
[self.author_renamed_with_book, self.book_with_field_and_author_renamed],
MigrationQuestioner({"ask_rename": True, "ask_rename_model": True}),
)
# Right number/type of migrations?
self.assertNumberMigrations(changes, 'testapp', 1)
self.assertOperationTypes(changes, 'testapp', 0, ["RenameModel"])
self.assertOperationAttributes(changes, 'testapp', 0, 0, old_name="Author", new_name="Writer")
# Right number/type of migrations for related field rename?
# Alter is already taken care of.
self.assertNumberMigrations(changes, 'otherapp', 1)
self.assertOperationTypes(changes, 'otherapp', 0, ["RenameField"])
self.assertOperationAttributes(changes, 'otherapp', 0, 0, old_name="author", new_name="writer")
示例4: __init__
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def __init__(self, from_state, to_state, questioner=None):
self.from_state = from_state
self.to_state = to_state
self.questioner = questioner or MigrationQuestioner()
示例5: __init__
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def __init__(self, from_state, to_state, questioner=None):
self.from_state = from_state
self.to_state = to_state
self.questioner = questioner or MigrationQuestioner()
self.existing_apps = {app for app, model in from_state.models}
示例6: test_ask_initial_with_disabled_migrations
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def test_ask_initial_with_disabled_migrations(self):
questioner = MigrationQuestioner()
self.assertIs(False, questioner.ask_initial('migrations'))
示例7: test_rename_field
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def test_rename_field(self):
"""Tests autodetection of renamed fields."""
changes = self.get_changes(
[self.author_name], [self.author_name_renamed], MigrationQuestioner({"ask_rename": True})
)
# Right number/type of migrations?
self.assertNumberMigrations(changes, 'testapp', 1)
self.assertOperationTypes(changes, 'testapp', 0, ["RenameField"])
self.assertOperationAttributes(changes, 'testapp', 0, 0, old_name="name", new_name="names")
示例8: test_rename_model
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def test_rename_model(self):
"""Tests autodetection of renamed models."""
changes = self.get_changes(
[self.author_with_book, self.book],
[self.author_renamed_with_book, self.book_with_author_renamed],
MigrationQuestioner({"ask_rename_model": True}),
)
# Right number/type of migrations?
self.assertNumberMigrations(changes, 'testapp', 1)
self.assertOperationTypes(changes, 'testapp', 0, ["RenameModel"])
self.assertOperationAttributes(changes, 'testapp', 0, 0, old_name="Author", new_name="Writer")
# Now that RenameModel handles related fields too, there should be
# no AlterField for the related field.
self.assertNumberMigrations(changes, 'otherapp', 0)
示例9: test_rename_m2m_through_model
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def test_rename_m2m_through_model(self):
"""
Tests autodetection of renamed models that are used in M2M relations as
through models.
"""
changes = self.get_changes(
[self.author_with_m2m_through, self.publisher, self.contract],
[self.author_with_renamed_m2m_through, self.publisher, self.contract_renamed],
MigrationQuestioner({'ask_rename_model': True})
)
# Right number/type of migrations?
self.assertNumberMigrations(changes, 'testapp', 1)
self.assertOperationTypes(changes, 'testapp', 0, ['RenameModel'])
self.assertOperationAttributes(changes, 'testapp', 0, 0, old_name='Contract', new_name='Deal')
示例10: test_rename_model_with_fks_in_different_position
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def test_rename_model_with_fks_in_different_position(self):
"""
#24537 - The order of fields in a model does not influence
the RenameModel detection.
"""
before = [
ModelState("testapp", "EntityA", [
("id", models.AutoField(primary_key=True)),
]),
ModelState("testapp", "EntityB", [
("id", models.AutoField(primary_key=True)),
("some_label", models.CharField(max_length=255)),
("entity_a", models.ForeignKey("testapp.EntityA", models.CASCADE)),
]),
]
after = [
ModelState("testapp", "EntityA", [
("id", models.AutoField(primary_key=True)),
]),
ModelState("testapp", "RenamedEntityB", [
("id", models.AutoField(primary_key=True)),
("entity_a", models.ForeignKey("testapp.EntityA", models.CASCADE)),
("some_label", models.CharField(max_length=255)),
]),
]
changes = self.get_changes(before, after, MigrationQuestioner({"ask_rename_model": True}))
self.assertNumberMigrations(changes, "testapp", 1)
self.assertOperationTypes(changes, "testapp", 0, ["RenameModel"])
self.assertOperationAttributes(changes, "testapp", 0, 0, old_name="EntityB", new_name="RenamedEntityB")
示例11: test_keep_db_table_with_model_change
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def test_keep_db_table_with_model_change(self):
"""
Tests when model changes but db_table stays as-is, autodetector must not
create more than one operation.
"""
changes = self.get_changes(
[self.author_with_db_table_options],
[self.author_renamed_with_db_table_options],
MigrationQuestioner({"ask_rename_model": True}),
)
# Right number/type of migrations?
self.assertNumberMigrations(changes, 'testapp', 1)
self.assertOperationTypes(changes, 'testapp', 0, ["RenameModel"])
self.assertOperationAttributes(changes, "testapp", 0, 0, old_name="Author", new_name="NewAuthor")
示例12: test_alter_db_table_with_model_change
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def test_alter_db_table_with_model_change(self):
"""
Tests when model and db_table changes, autodetector must create two
operations.
"""
changes = self.get_changes(
[self.author_with_db_table_options],
[self.author_renamed_with_new_db_table_options],
MigrationQuestioner({"ask_rename_model": True}),
)
# Right number/type of migrations?
self.assertNumberMigrations(changes, 'testapp', 1)
self.assertOperationTypes(changes, 'testapp', 0, ["RenameModel", "AlterModelTable"])
self.assertOperationAttributes(changes, "testapp", 0, 0, old_name="Author", new_name="NewAuthor")
self.assertOperationAttributes(changes, "testapp", 0, 1, name="newauthor", table="author_three")
示例13: test_rename_field_foreign_key_to_field
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def test_rename_field_foreign_key_to_field(self):
before = [
ModelState('app', 'Foo', [
('id', models.AutoField(primary_key=True)),
('field', models.IntegerField(unique=True)),
]),
ModelState('app', 'Bar', [
('id', models.AutoField(primary_key=True)),
('foo', models.ForeignKey('app.Foo', models.CASCADE, to_field='field')),
]),
]
after = [
ModelState('app', 'Foo', [
('id', models.AutoField(primary_key=True)),
('renamed_field', models.IntegerField(unique=True)),
]),
ModelState('app', 'Bar', [
('id', models.AutoField(primary_key=True)),
('foo', models.ForeignKey('app.Foo', models.CASCADE, to_field='renamed_field')),
]),
]
changes = self.get_changes(before, after, MigrationQuestioner({'ask_rename': True}))
# Right number/type of migrations?
self.assertNumberMigrations(changes, 'app', 1)
self.assertOperationTypes(changes, 'app', 0, ['RenameField'])
self.assertOperationAttributes(changes, 'app', 0, 0, old_name='field', new_name='renamed_field')
示例14: test_rename_field_preserved_db_column
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def test_rename_field_preserved_db_column(self):
"""
RenameField is used if a field is renamed and db_column equal to the
old field's column is added.
"""
before = [
ModelState('app', 'Foo', [
('id', models.AutoField(primary_key=True)),
('field', models.IntegerField()),
]),
]
after = [
ModelState('app', 'Foo', [
('id', models.AutoField(primary_key=True)),
('renamed_field', models.IntegerField(db_column='field')),
]),
]
changes = self.get_changes(before, after, MigrationQuestioner({'ask_rename': True}))
self.assertNumberMigrations(changes, 'app', 1)
self.assertOperationTypes(changes, 'app', 0, ['RenameField', 'AlterField'])
self.assertOperationAttributes(
changes, 'app', 0, 0, model_name='foo', old_name='field', new_name='renamed_field',
)
self.assertOperationAttributes(changes, 'app', 0, 1, model_name='foo', name='renamed_field')
self.assertEqual(changes['app'][0].operations[-1].field.deconstruct(), (
'renamed_field', 'django.db.models.IntegerField', [], {'db_column': 'field'},
))
示例15: test_rename_model_reverse_relation_dependencies
# 需要導入模塊: from django.db.migrations import questioner [as 別名]
# 或者: from django.db.migrations.questioner import MigrationQuestioner [as 別名]
def test_rename_model_reverse_relation_dependencies(self):
"""
The migration to rename a model pointed to by a foreign key in another
app must run after the other app's migration that adds the foreign key
with model's original name. Therefore, the renaming migration has a
dependency on that other migration.
"""
before = [
ModelState('testapp', 'EntityA', [
('id', models.AutoField(primary_key=True)),
]),
ModelState('otherapp', 'EntityB', [
('id', models.AutoField(primary_key=True)),
('entity_a', models.ForeignKey('testapp.EntityA', models.CASCADE)),
]),
]
after = [
ModelState('testapp', 'RenamedEntityA', [
('id', models.AutoField(primary_key=True)),
]),
ModelState('otherapp', 'EntityB', [
('id', models.AutoField(primary_key=True)),
('entity_a', models.ForeignKey('testapp.RenamedEntityA', models.CASCADE)),
]),
]
changes = self.get_changes(before, after, MigrationQuestioner({'ask_rename_model': True}))
self.assertNumberMigrations(changes, 'testapp', 1)
self.assertMigrationDependencies(changes, 'testapp', 0, [('otherapp', '__first__')])
self.assertOperationTypes(changes, 'testapp', 0, ['RenameModel'])
self.assertOperationAttributes(changes, 'testapp', 0, 0, old_name='EntityA', new_name='RenamedEntityA')