Django无法解析相关的Mod

2024-04-16 20:02:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚刚在一个名为“标准”的应用程序中添加了一个名为“购买者”的新模型。我运行makemigrations,一切正常,然后我尝试运行migrate,得到以下错误:

    Running migrations:
  Applying tracking.0002_auto_20180418_1909...Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\commands\migrate.py", line 200, in handle
    fake_initial=fake_initial,
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\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 "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\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 "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\migrations\migration.py", line 122, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\migrations\operations\fields.py", line 216, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\backends\base\schema.py", line 481, in alter_field
    new_db_params = new_field.db_parameters(connection=self.connection)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\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 "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 963, in db_type
    return self.target_field.rel_db_type(connection=connection)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 877, in target_field
    return self.foreign_related_fields[0]
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 634, in foreign_related_fields
    return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 621, in related_fields
    self._related_fields = self.resolve_related_fields()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 606, in resolve_related_fields
    raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model 'standard.Purchaser' cannot be resolved

以下是购买者的模型:

^{2}$

这里是添加了它的迁移:

# Generated by Django 2.0.2 on 2018-04-19 02:09

from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('for', '0020_auto_20180418_1909'),
        ('match', '0013_auto_20180418_1909'),
        ('direct', '0006_auto_20180418_1909'),
        ('comp', '0074_auto_20180305_1740'),
        ('track', '0002_auto_20180418_1909'),
        ('even', '0040_auto_20180418_1909'),
        ('standard', '0037_auto_20180404_2012'),
    ]

    operations = [
        migrations.CreateModel(
            name='Purchaser',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('desc', models.TextField(blank=True, null=True)),
                ('job_title', models.CharField(max_length=64)),
                ('company_name', models.CharField(max_length=64)),
                ('company_type', models.IntegerField(blank=True, choices=[(0, 'Startup/Innovator/Insurtech'), (1, 'Provider'), (2, 'Accelerator'), (3, 'Incubator'), (4, 'Rating_agency'), (5, 'Carrier'), (6, 'Regulator'), (7, 'News Source'), (8, 'Trade Association'), (9, 'Reinsurer'), (10, 'TPA'), (11, 'VC'), (12, 'Agent/Broker'), (13, 'Advisory'), (14, 'Consultancy'), (15, 'Investor'), (16, 'person'), (17, 'Other'), (18, 'Technology Provider'), (19, 'Education & Training')], null=True)),
                ('time_zone', models.CharField(blank=True, max_length=64, null=True)),
                ('phone_number', models.CharField(blank=True, max_length=64, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.", regex='^\\+?1?\\d{9,15}$')])),
                ('image', models.ImageField(blank=True, null=True, upload_to='employees')),
                ('cover_image', models.ImageField(blank=True, help_text='A 1300 width by 300 height top cover image.', null=True, upload_to='employees', verbose_name='Cover Image')),
                ('linkedin_id', models.CharField(blank=True, max_length=255, null=True)),
                ('pay_token', models.CharField(blank=True, max_length=255, null=True)),
                ('stripe_customer_id', models.CharField(blank=True, max_length=255, null=True)),
                ('paid_till_date', models.DateTimeField(blank=True, null=True)),
                ('linkedin_url', models.URLField(blank=True, max_length=255, null=True)),
                ('facebook_url', models.URLField(blank=True, max_length=255, null=True)),
                ('twitter_url', models.URLField(blank=True, max_length=255, null=True)),
                ('url', models.URLField(blank=True, max_length=255, null=True)),
                ('company_url', models.URLField(blank=True, max_length=255, null=True)),
                ('registered', models.BooleanField(default=False)),
                ('subscription_current', models.BooleanField(default=False)),
                ('paid', models.BooleanField(default=False)),
                ('coupon', models.CharField(blank=True, max_length=64, null=True)),
                ('terms', models.BooleanField(default=True)),
                ('invoice_requested', models.BooleanField(default=False)),
                ('detail_completed', models.BooleanField(default=False)),
                ('categories_completed', models.BooleanField(default=False)),
                ('jobs_completed', models.BooleanField(default=False)),
                ('education_completed', models.BooleanField(default=False)),
                ('boards_completed', models.BooleanField(default=False)),
                ('articles_completed', models.BooleanField(default=False)),
                ('invite_completed', models.BooleanField(default=False)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('company', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='company_employee', to='comp.Company')),
                ('user', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Person',
            },
        ),
        migrations.RemoveField(
            model_name='employ',
            name='brand',
        ),
        migrations.RemoveField(
            model_name='employ',
            name='company',
        ),
        migrations.RemoveField(
            model_name='employ',
            name='user',
        ),
        migrations.AlterField(
            model_name='contact',
            name='employee',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='cstandard.Purchaser'),
        ),
        migrations.AlterField(
            model_name='invite',
            name='employee',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='standard.Purchaser'),
        ),
        migrations.AlterField(
            model_name='resetpassemail',
            name='employee',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='standard.Purchaser'),
        ),
        migrations.AlterField(
            model_name='resetpassdemail',
            name='request_token',
            field=models.CharField(default='jN1D4G0qKCpTexaJWhHhil8qAobmzdu8', max_length=32, unique=True),
        ),
        migrations.AlterField(
            model_name='transact',
            name='employee',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='standard.Purchaser'),
        ),
        migrations.AlterField(
            model_name='transactalertemail',
            name='actor',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='actor', to='stanndard.Purchaser'),
        ),
        migrations.AlterField(
            model_name='welcomeem',
            name='employee',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='standard.Purchaser'),
        ),
        migrations.DeleteModel(
            name='Employ',
        ),
    ]

基于互联网搜索,我尝试过: 在迁移中添加和删除auth_user_模型, 更改设置中应用程序的顺序 有人看到这个问题了吗?我快疯了。在

提前谢谢。在


Tags: djangonameinpytruefielddbmodels