1
應用遷移時出現錯誤django.db.migrations.graph.CircularDependencyError
。值得注意的是,我從一個空的數據庫開始。Django循環依賴
我也設法歸結到導致錯誤的類,這似乎是OAuthAccessToken
。
class OAuthAccessToken(Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='oauth_access_tokens',
help_text=_('User'))
provider = models.ForeignKey(Provider, related_name='oauth_access_tokens',
help_text=_('OAuth provider'))
token = fields.SafeRandomField(max_length=32,
help_text=_('Access token'))
上面的代碼只有在註釋provider
聲明時纔有效。 Provider
類來自allaccess框架。下面是它的聲明:其他
@python_2_unicode_compatible
class Provider(models.Model):
"Configuration for OAuth provider."
name = models.CharField(max_length=50, unique=True)
request_token_url = models.CharField(blank=True, max_length=255)
authorization_url = models.CharField(max_length=255)
access_token_url = models.CharField(max_length=255)
profile_url = models.CharField(max_length=255)
consumer_key = EncryptedField(blank=True, null=True, default=None)
consumer_secret = EncryptedField(blank=True, null=True, default=None)
一種方法對我來說,使代碼工作是,如果我從我的設置文件刪除AUTH_USER_MODEL = 'api.User'
,在這種情況下,第一個代碼示例工程。
的事情是,我檢查了遷移,並發現這一點:
migrations.CreateModel(
name='OAuthAccessToken',
fields=[
('uid', rest.fields.IDField(default=rest.fields.GenerateID(15, b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), max_length=15, serialize=False, primary_key=True, help_text='Server generated public unique ID')),
('creation_date', models.DateTimeField(help_text='Creation date', auto_now_add=True)),
('last_update', models.DateTimeField(help_text='Last update', auto_now=True)),
('token', rest.fields.SafeRandomField(default=rest.fields.GenerateID(32, b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), help_text='Access token', max_length=32)),
('provider', models.ForeignKey(related_name='oauth_access_tokens', to='allaccess.Provider', help_text='OAuth provider')),
('user', models.OneToOneField(related_name='oauth_access_tokens', to=settings.AUTH_USER_MODEL, help_text='User')),
],
options={
'abstract': False,
},
bases=(models.Model,),
),
但我沒有看到其中圓形依賴性。
編輯:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/migrate.py", line 106, in handle
plan = executor.migration_plan(targets)
File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 49, in migration_plan
for migration in self.loader.graph.forwards_plan(target):
File "/Library/Python/2.7/site-packages/django/db/migrations/graph.py", line 55, in forwards_plan
return self.dfs(node, lambda x: self.dependencies.get(x, set()))
File "/Library/Python/2.7/site-packages/django/db/migrations/graph.py", line 105, in dfs
raise CircularDependencyError()
django.db.migrations.graph.CircularDependencyError
編輯:更新使用Django 1.7.7
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/migrate.py", line 106, in handle
plan = executor.migration_plan(targets)
File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 54, in migration_plan
for migration in self.loader.graph.forwards_plan(target):
File "/Library/Python/2.7/site-packages/django/db/migrations/graph.py", line 60, in forwards_plan
return self.dfs(node, lambda x: self.dependencies.get(x, set()))
File "/Library/Python/2.7/site-packages/django/db/migrations/graph.py", line 124, in dfs
self.ensure_not_cyclic(start, get_children)
File "/Library/Python/2.7/site-packages/django/db/migrations/graph.py", line 112, in ensure_not_cyclic
raise CircularDependencyError(", ".join("%s.%s" % n for n in cycle))
django.db.migrations.graph.CircularDependencyError: api.0001_initial, allaccess.0001_initial
你能發佈完整的錯誤信息嗎?有關您的遷移的更多信息也會有所幫助,特別是在依賴性方面。 – knbk 2015-04-05 18:39:03
@mu無盡管在不同的車型上,所以這沒問題。 – knbk 2015-04-05 18:39:29
@mu無我已經嘗試了不同的名字,沒有效果 – 2015-04-05 18:42:56