不幸的是,在迁移Django迁移文件时遇到了一些问题,因为对于这个极其特定的数据库,我有太多模型。因此,我有6个迁移文件。我之所以有这么多,是因为“模型太多”。我正在尝试推断无法迁移的原因,我相信是1)(给我的指针)堆栈溢出和2)内存。
这是我要删除的迁移文件中的代码:
operations = [
migrations.AlterField(
model_name='pnote1',
name='status',
field=models.CharField(choices=[('5', 'test5'), ('4', 'test4'), ('3', 'test3'), ('6', 'test6'), ('1', 'test1'), ('2', 'test2')], default='1', max_length=1),
),
这些AlterField中有100个。我想知道是否可以删除它们而不会损害数据库。即使没有任何更改,拥有这些AlterField也似乎是多余的。这些模型(从抽象模型继承而来)具有:
option = models.CharField(max_length=1, choices=TYPE, default='1')
我最初选择的顺序是1-6,而不是混乱。在每个迁移文件中,migrations.AlterField的数量由于某些奇怪的原因而不断增加。再说一遍,我可以删除它而不损害数据库吗?
编辑:这是我要迁移的时间,而不是进行迁移。
Fatal Python error: Cannot recover from stack overflow.
Current thread 0x00001528 (most recent call first):
File "c:\users\test\appdata\local\programs\python\python37-32\Lib\contextlib.py", line 130 in __exit__
File "C:\Users\test\test\testvenv\lib\site-packages\django\db\migrations\state.py", line 318 in render_multiple
File "C:\Users\test\test\testvenv\lib\site-packages\django\db\migrations\state.py", line 191 in _reload
File "C:\Users\test\test\testvenv\lib\site-packages\django\db\migrations\state.py", line 158 in reload_model
File "C:\Users\test\test\testvenv\lib\site-packages\django\db\migrations\state.py", line 97 in add_model
File "C:\Users\test\test\testvenv\lib\site-packages\django\db\migrations\operations\models.py", line 86 in state_forwards
File "C:\Users\test\test\testvenv\lib\site-packages\django\db\migrations\migration.py", line 114 in apply
File "C:\Users\test\test\testvenv\lib\site-packages\django\db\migrations\executor.py", line 245 in apply_migration
File "C:\Users\test\test\testvenv\lib\site-packages\django\db\migrations\executor.py", line 147 in _migrate_all_forwards
File "C:\Users\test\test\testvenv\lib\site-packages\django\db\migrations\executor.py", line 117 in migrate
File "C:\Users\test\test\testvenv\lib\site-packages\django\core\management\commands\migrate.py", line 234 in handle
File "C:\Users\test\test\testvenv\lib\site-packages\django\core\management\base.py", line 83 in wrapped
File "C:\Users\test\test\testvenv\lib\site-packages\django\core\management\base.py", line 364 in execute
File "C:\Users\test\test\testvenv\lib\site-packages\django\core\management\base.py", line 323 in run_from_argv
File "C:\Users\test\test\testvenv\lib\site-packages\django\core\management\__init__.py", line 375 in execute
File "C:\Users\test\test\testvenv\lib\site-packages\django\core\management\__init__.py", line 381 in execute_from_command_line
File "manage.py", line 17 in main
File "manage.py", line 21 in <module>
Edit2:
class Stick1(models.Model):
TYPE = {
('1', 'test1'),
('2', 'test2'),
('3', 'test3'),
('4', 'test4'),
('5', 'test5'),
('6', 'test6'),
}
option = models.CharField(max_length=1, choices=TYPE, default='1')