简体   繁体   English

在不存在的模型字段上获取迁移错误

[英]Getting Migrate Error on Model Field that doesn't exist

Ran my server today and realized I had 'two unapplied migrations'. 今天运行我的服务器,意识到我有“两个未应用的迁移”。 I ran the command makemigrations and it detected no change, so naturally I then ran migrate. 我运行了命令makemigrations,但未检测到更改,因此自然而然地运行了迁移。

I get this error code on my terminal: 我在终端上收到以下错误代码:

Applying Campaigns.0016_campaignrecruit_date...Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", l
ine 371, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", l
ine 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py", line
288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py", line
335, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/migrat
e.py", line 200, in handle
    fake_initial=fake_initial,
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/executor.py", lin
e 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/executor.py", lin
e 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/executor.py", lin
e 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/migration.py", li
ne 122, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/operations/fields
.py", line 84, in database_forwards
    field,
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py",
 line 306, in add_field
    self._remake_table(model, create_field=field)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py",
 line 178, in _remake_table

    self.effective_default(create_field)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/base/schema.py", li
ne 240, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 767, in get_db_prep_save
    return self.get_db_prep_value(value, connection=connection, prepared=False)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 1276, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 1271, in get_prep_value
    return self.to_python(value)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 1233, in to_python
parsed = parse_date(value)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/dateparse.py", line 74, i
n parse_date
    match = date_re.match(value)
TypeError: expected string or bytes-like object

So to me, it looks like a date field in my model campaignrecruit is getting an input that it doesn't know how to handle. 因此,对我来说,我的模型CampaignRecruit中的日期字段似乎收到了一个不知道如何处理的输入。 Which I would understand. 我会明白的。 But the thing is I don't have a datefield in my campaignrecruit model. 但问题是我的CampaignRecruit模型中没有日期字段。 The Time field is intentionally commented out right now. 现在刻意将“时间”字段注释掉。

Here's my models.py: 这是我的models.py:

class campaignrecruit(models.Model):
    campaign = models.ForeignKey(startcampaign, on_delete=models.CASCADE)
    volunteer = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    join = models.BooleanField()
    #Time = models.IntegerField()
    def __str__(self):
        return str(self.volunteer)

What else would throw this error? 还有什么会引发此错误? Any and all help is appreciated. 任何和所有帮助表示赞赏。

Since no one else answered, I will. 既然没有人回答,我会的。 As Aritra stated, I totally forgot about the migration files that are created whenever you run the migrate command. 正如Aritra所说,我完全忘记了每当您运行migration命令时创建的迁移文件。 I had removed these model fields from my models and whenever I migrated again there was an error removing the files in my migrations file. 我已经从模型中删除了这些模型字段,并且每当我再次迁移时,删除迁移文件中的文件都会出错。 After manually going in and removing the files, my error was fixed. 手动进入并删除文件后,我的错误已修复。

The database was just out of sync with what django had in its files. 该数据库与django文件中的内容不同步。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django model 字段与其他不存在的 model 字段冲突? - Django model field clashes with other model field that doesn't exist? django-在查询集中的字段中添加模型中不存在的字段 - django - prepending a field in the query set that doesn't exist in the model Django:将列添加到模型中导致该列不存在的错误 - Django: Adding column to model giving error that the column doesn't exist 尝试在 DRF 中保存时在我的 uuid(主键)上出现“不存在或为 m2m 字段”错误 - Getting “doesn't exist or is m2m field” error on my uuid (primary key) when trying to save in DRF ShopifyQL 引发错误“类型‘QueryRoot’上不存在字段‘shopifyqlQuery’” - ShopifyQL raise error "Field 'shopifyqlQuery' doesn't exist on type 'QueryRoot'" 尝试创建文件时出现“文件不存在”错误 - Getting a "File doesn't exist" error when trying to create a file 如果字段不存在,则返回 null - Return null if the field doesn't exist 如果字段不存在,则更新 MongoDB 文档 - Updating a MongoDB document if field doesn't exist 在创建具有相关模型中不存在的多对多字段选择的 Django 模型对象时,如何防止表单提交? - How to keep a form from submitting when creating a Django model object with many-to-many field selection that is doesn't exist in the related model? 如何修复“ID 为“某些 id”的项目不存在”Django FileField model 错误 - How to fix “Project with ID ”some id“ doesn't exist” Django FileField model error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM