1
我有一个模型的DateField工作得很好。我想将它从DateField更改为CharField。更改Django模型属性,现在得到它的错误
前:
class NWEAScore(models.Model):
test_date = models.DateField(default=date.today, verbose_name='Test Date')
后:
class NWEAScore(models.Model):
year = models.CharField(max_length=50, choices=YEAR_CHOICES, default=SIXTEEN)
season = models.CharField(max_length=50, choices=SESSION_CHOICES, default=FALL)
不知道哪里出了问题,但现在我得到一个错误。
进行移植不成问题。我制作它们,然后将它们上传到我的服务器,然后在迁移时出现错误。 我得到当我尝试运用我的迁徙中的错误:
(venv) [email protected]:~/newton$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, amc, auth, brain, contenttypes, ixl, nwea, sessions
Running migrations:
Rendering model states... DONE
Applying brain.0021_auto_20160927_0038... OK
Applying nwea.0011_auto_20160927_0038...Traceback (most recent call last):
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/models/options.py", line 612, in get_field
return self.fields_map[field_name]
KeyError: 'test_date'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/core/management/base.py", line 305, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/core/management/base.py", line 356, in execute
output = self.handle(*args, **options)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 202, in handle
targets, plan, fake=fake, fake_initial=fake_initial
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 97, in migrate
state = self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 132, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 237, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/migrations/operations/models.py", line 525, in database_forwards
getattr(new_model._meta, self.option_name, set()),
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 329, in alter_unique_together
self._delete_composed_index(model, fields, {'unique': True}, self.sql_delete_unique)
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 352, in _delete_composed_index
columns = [model._meta.get_field(field).column for field in fields]
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 352, in <listcomp>
columns = [model._meta.get_field(field).column for field in fields]
File "/home/alex/newton/venv/lib/python3.4/site-packages/django/db/models/options.py", line 614, in get_field
raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: NWEAScore has no field named 'test_date'
我经历了,并删除了我的所有实例从我的所有车型,只是柜面剩余“NWEAScore”实例与test_date被扔的错误。
我在整个项目中搜索了术语“test_date”,试图删除每个实例,而剩下的只有在旧迁移中的实例。我应该回去删除那些吗?那可以抛弃吗?如果是这样,我不清楚如何擦除迁移并创建新迁移。
我给了它一个镜头几天,如果有人有提前感谢的建议!
要争取 - 即使是0001_initial.py,对不对? –
@AlexTrost是的,那也是 –
删除它并运行迁移。它创造了一个新的0001_initial.py,给了我这样的: '(牛顿)TrostMacbook:牛顿alexandertrost $蟒蛇manage.py makemigrations 迁移为 'nwea': nwea /迁移/ 0001_initial.py: - 创建模型NWEAScore - 创建模型nWEASkill - 创建模型RITBand - 添加字段rit_band到nweaskill - 改变unique_together为nweascore(1个约束(S))' –