这是我创建的第一个模型
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)
但是,我将' IP地址' 的型号名称更改为' 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'.
如何解决此问题?
我正在使用:
Django 1.10.5
Postgresql
Python 2.7
答案 0 :(得分:3)
我自己正在努力解决这样的僵局,继续得到“ValueError:字段......被宣布为懒惰引用'...',但app'......'不提供模型'.. '。“
在深入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>'), <===
),
此外,我必须正确设置应用程序之间的依赖关系,因此,例如,AlterField应该依赖于显然创建该模型的迁移。不要问我为什么它不能开箱即用,我只需要经历这个....
保
答案 1 :(得分:1)
解决方案是访问数据库中的django_migrations表并删除导致此错误的迁移。然后转到特定的应用迁移文件夹并删除特定的迁移
这是最后一个选项
./manage.py migrate specific_app <specific_migration_to_rollback_to>
无效,这是django 1.10版本中的常见问题
答案 2 :(得分:0)
Django 1.11解决了这个问题。 (或者至少,它适合我。)
答案 3 :(得分:0)
我的问题是PyCharm的重构有点激进,并更改了实际迁移文件中的模型参考。恢复了已更改的迁移,并能够继续进行。
以防万一这有助于使用较新版本的Django(通常可以正常处理模型重命名)的任何人。