这是我创建的第一个模型
class IPAddresses(models.Model):
'''
@brief Class for ip addresses.
@attrs name Can be company name
'''
ip = models.GenericIPAddressField()
name = models.CharField(max_length=150, null=True, blank=True)
active = models.BooleanField(default=True)
def __unicode__(self):
return self.ip
class Authentication(models.Model):
'''
@brief Custom Authentication for dashboard
@attrs name can be a name of a person
'''
name = models.CharField(max_length=100, null=True, blank=True)
password = models.CharField(max_length=200, unique=True)
ip = models.ManyToManyField(IPAddresses, blank=True)
Run Code Online (Sandbox Code Playgroud)
但是,我将“IPAddresses”的模型名称更改为“IPAddress”并运行迁移。很好,但是我的下一次迁移不是,并且一直收到此值错误:
Apply all migrations: admin, auth, cache_admin, contenttypes, core, provider, saba_dashboard, sessions
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/deanchristianarmada/Desktop/projects/asian_gaming/radar/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Users/deanchristianarmada/Desktop/projects/asian_gaming/radar/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/deanchristianarmada/Desktop/projects/asian_gaming/radar/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/deanchristianarmada/Desktop/projects/asian_gaming/radar/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/Users/deanchristianarmada/Desktop/projects/asian_gaming/radar/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 164, in handle
pre_migrate_apps = pre_migrate_state.apps
File "/Users/deanchristianarmada/Desktop/projects/asian_gaming/radar/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/deanchristianarmada/Desktop/projects/asian_gaming/radar/lib/python2.7/site-packages/django/db/migrations/state.py", line 176, in apps
return StateApps(self.real_apps, self.models)
File "/Users/deanchristianarmada/Desktop/projects/asian_gaming/radar/lib/python2.7/site-packages/django/db/migrations/state.py", line 249, in __init__
raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field saba_dashboard.Authentication.ip was declared with a lazy reference to 'core.ipaddresses', but app 'core' doesn't provide model 'ipaddresses'.
The field saba_dashboard.Authentication_ip.ipaddresses was declared with a lazy reference to 'core.ipaddresses', but app 'core' doesn't provide model 'ipaddresses'.
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我正在使用:
Django 1.10.5
Postgresql
Python 2.7
Run Code Online (Sandbox Code Playgroud)
我自己一直在为这样的僵局而苦苦挣扎,不断收到“ValueError:该字段...被声明为对'...'的懒惰引用,但应用程序'...'不提供模型'...'。 ”。
在深入 pgadmin 并删除/恢复一些表后,我实际上发现它也可以通过添加一个新的迁移来解决,该迁移告诉 django 引用的模型已更改:
migrations.AlterField(
model_name='...',
name='...',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='...', to='<app>.<new-model>'), <===
),
Run Code Online (Sandbox Code Playgroud)
此外,我必须正确设置应用程序之间的依赖关系,因此例如 AlterField 显然应该依赖于创建该模型的迁移。不要问我为什么它不能开箱即用,我只是不得不经历这个......
保罗
归档时间: |
|
查看次数: |
4976 次 |
最近记录: |