7
我試圖在使用Field.db_index
的模型字段中爲已遷移的應用程序添加索引。看着Django's documentation所有我需要做的是設置db_index=True
:使用遷移將索引添加到Django中的模型字段
class Person(models.Model):
first_name = models.CharField()
last_name = models.CharField(db_index=True)
,然後我第一次嘗試新的Django的遷移:
./manage.py makemigrations app-name
但遷移似乎沒有注意到的改變,也不會增加用於創建索引的sql命令。所以,我想django-admin.py
作爲解釋here:
django-admin.py sqlindexes app-name
但是,這並不無論是打印的SQL命令,並將其與以下錯誤退出:
CommandError: App 'app-name' has migrations. Only the sqlmigrate and sqlflush commands can be used when an app has migrations.