首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ValueError:无法解析相关模型“”referrals.Referral“”

ValueError:无法解析相关模型“”referrals.Referral“”
EN

Stack Overflow用户
提问于 2019-04-16 06:51:18
回答 1查看 160关注 0票数 1

当我试图在我的heroku服务器上运行python manage.py migrate时,我得到了标题中显示的错误(迁移在本地运行得很好)。

完整回溯:

代码语言:javascript
复制
Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying engine.0051_userprofile_referral... OK
  Applying engine.0052_auto_20190414_0131...Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 234, in handle
    fake_initial=fake_initial,
  File "/app/.heroku/python/lib/python3.6/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 "/app/.heroku/python/lib/python3.6/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 "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 249, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 507, in alter_field
    new_db_params = new_field.db_parameters(connection=self.connection)
  File "/app/.heroku/python/lib/python3.6/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 "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/related.py", line 963, in db_type
    return self.target_field.rel_db_type(connection=connection)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/related.py", line 878, in target_field
    return self.foreign_related_fields[0]
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/related.py", line 632, in foreign_related_fields
    return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/related.py", line 619, in related_fields
    self._related_fields = self.resolve_related_fields()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/related.py", line 604, in resolve_related_fields
    raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model 'referrals.Referral' cannot be resolved

以下是迁移引擎。0052:

由Django 2.2于2019-04-14 01:31生成

代码语言:javascript
复制
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('engine', '0051_userprofile_referral'),
    ]

    operations = [
        migrations.AlterField(
            model_name='userprofile',
            name='referral',
            field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='referrals.Referral'),
        ),
    ]

和我的models.py,相关的部分:

代码语言:javascript
复制
class UserProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    slug = models.SlugField(max_length=50, blank=True, null=True)
    following = models.ManyToManyField(User, related_name="followers")

    full_name = models.CharField(max_length=50, blank=True, null=True)
    thumbnail = models.ImageField(
        upload_to="userprofile_thumbnails/", blank=True, null=True)
    bio = models.TextField(blank=True, null=True)
    paypal_email = models.EmailField(blank=True, null=True)
    #balance = models.BigIntegerField(blank=True, null=True)
    #total_earned = models.BigIntegerField(blank=True, null=True)
    registration_ip = models.GenericIPAddressField(blank=True, null=True)

    referral = models.OneToOneField(
        Referral, blank=True, null=True, on_delete=models.CASCADE)

有人能帮上忙吗?referrals是包pinax.referrals:https://github.com/pinax/pinax-referrals

它有一个我正在使用的名为Referral的模型。同样,迁移在本地运行良好,尽管在heroku生产中不是这样。请帮帮忙。提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-04-16 07:11:54

('referrals', '__first__')添加到我的依赖项中,这起作用了。(不再有错误)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55698252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档