model 中新增了一个对象 Message 和 并在另一个model中增加外键字段message,然后push到heroku上,同步migrate之后,发现新的表不能用. 但是本地是执行 python manage.py flush 之后同步的,没出问题, 但是在heroku上执行 flush 出错
CommandError: Database d4e4561s5hscht couldn't be flushed. Possible reasons:
* The database isn't running or isn't configured correctly.
* At least one of the expected database tables doesn't exist.
* The SQL was invalid.
Hint: Look at the output of 'django-admin sqlflush'. That's the SQL this command wasn't able to run.
The full error: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "blog_post" references "auth_user".
HINT: Truncate table "blog_post" at the same time, or use TRUNCATE ... CASCADE.
请问怎么清理数据库
PHP中文网2017-04-17 15:23:26
There is a field foreign key in the "blog_post" table that is associated with the "auth_user" table.
Flush is for truncate table. Of course, the auth_user table cannot truncate if it has data.
The usual approach in the current version is:
python manage.py makemigrations
python manage.py migrate
That’s it. I don’t know what LZ said “after migrating, the new watch cannot be used”
Why flush? Everything is already online. Still need to clear the data?