我的models.py文件,Django的數據庫遷移問題 - 缺少 「移民類」 錯誤
class Dag(models.Model):
dag_id = models.CharField(primary_key=True, max_length=250)
is_paused = models.IntegerField(blank=True, null=True)
is_subdag = models.IntegerField(blank=True, null=True)
is_active = models.IntegerField(blank=True, null=True)
last_scheduler_run = models.DateTimeField(blank=True, null=True)
last_pickled = models.DateTimeField(blank=True, null=True)
last_expired = models.DateTimeField(blank=True, null=True)
scheduler_lock = models.IntegerField(blank=True, null=True)
pickle_id = models.IntegerField(blank=True, null=True)
fileloc = models.CharField(blank=True, max_length=250)
owners = models.CharField(blank=True, max_length=250)
def _str_(self):
return self.dag_id
class Meta:
managed = True
db_table = 'dag'
我serializers.py文件,
class Dag_api_serializers(ModelSerializer):
class Meta:
model = Dag
fields = ('dag_id','is_paused','is_active','is_subdag','last_scheduler_run','last_pickled','last_expired','scheduler_lock','pickle_id','fileloc','owners')
同時給予條命令python manage.py migrate
或makemigrations
下面這樣的錯誤發生。我在我的車型之一db表,我希望他們通過這個命令遷移......在這裏我提到的錯誤消息的最後幾行
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\env\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
utility.execute()
File "C:\env\lib\site-packages\django\core\management\__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\env\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\env\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\env\lib\site-packages\django\core\management\commands\makemigrations.py", line 96, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "C:\env\lib\site-packages\django\db\migrations\loader.py", line 52, in __init__
self.build_graph()
File "C:\env\lib\site-packages\django\db\migrations\loader.py", line 203, in build_graph
self.load_disk()
File "C:\env\lib\site-packages\django\db\migrations\loader.py", line 117, in load_disk
"Migration %s in app %s has no Migration class" % (migration_name, app_config.label)
django.db.migrations.exceptions.BadMigrationError: Migration serializers in app snippets has no Migration class
在模型我指的是已經存在的表格。
@uthay嗨 - 你可以提供更多的代碼和信息?如果您使用自動遷移,這通常不會發生 - 您是否創建了自己的遷移?也請發佈完整的追溯(不只是最後幾行),並且發佈模型代碼也很有幫助。最後,由於數據庫遷移是一個Django問題(DRF剛剛從現有數據庫讀取),因此rest_framework似乎不會出現問題。 –
Infact堆棧溢出不允許我發佈整個回溯。我正在創建自己的遷移,但對於現有的表模型遷移,我也面臨同樣的問題。 – uthay
自動化遷移是否意味着對傳統數據庫的「-inspectdb」命令?我對嗎 ?無論如何,我不使用自動化。我使用ID MySQL的數據庫。 – uthay