我在我的一个应用程序中更改了模型的名称,现在当我去运行迁移时,它出错了,因为它运行的第一次迁移取决于更改的模型。我已在此处显示的settings.py安装的应用中检查了订单:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.contrib.sites',
'django.contrib.sitemaps',
'storages',
'rest_framework',
'rest_framework.authtoken',
'verification',
'comp',
'direct',
'comm',
'track',
'match',
'crawlers',
'event',
'c',
'forum',
'widget_tweaks',
]
'comm'是我首先需要迁移的应用,我已经多次运行:python manage.py makemigrations comm
然后python manage.py migrate comm
仍然没有运气。我唯一能想到的是依赖问题。以下是迁移模型的依赖关系:
dependencies = [
('direct', '0006_auto_20180420_1937'),
('match', '0013_auto_20180420_1937'),
('forum', '0020_auto_20180420_1937'),
('event', '0040_auto_20180420_1937'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('comm', '0037_auto_20180404_2012'),
('track', '0002_auto_20180420_1937'),
('comp', '0074_auto_20180305_1740'),
]
回溯: 要执行的操作:
Apply all migrations: comm
Running migrations:
Applying track.0002_auto_20180420_1937...Traceback (most recent call last):
File "manage.py", line 21, in <module>
execute_from_command_line(sys.argv)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\base.py", line 335, in execute
output = self.handle(*args, **options)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\commands\migrate.py", line 200, in handle
fake_initial=fake_initial,
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\migrations\migration.py", line 122, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\migrations\operations\fields.py", line 216, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\backends\base\schema.py", line 481, in alter_field
new_db_params = new_field.db_parameters(connection=self.connection)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 966, in db_parameters
return {"type": self.db_type(connection), "check": self.db_check(connection)}
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 963, in db_type
return self.target_field.rel_db_type(connection=connection)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 877, in target_field
return self.foreign_related_fields[0]
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 634, in foreign_related_fields
return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 621, in related_fields
self._related_fields = self.resolve_related_fields()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 606, in resolve_related_fields
raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model 'comm.Cust' cannot be resolved
Cust是我更改的模型,需要先迁移。
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('track', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='trackrequest',
name='emp',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='comm.Cust'),
),
]