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

时间:2019-04-15 22:51:18

标签: python django

当我尝试在heroku服务器上运行python manage.py migrate时,标题中显示了错误(迁移在本地工作正常)。

完整追溯:

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生成

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,相关部分:

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生产中。请帮忙。预先感谢。

1 个答案:

答案 0 :(得分:0)

('referrals', '__first__')添加到了我的依赖项中,此方法有效。 (没有更多错误)