构建:Heroku Python server,Postgresql 10.4,Django 2,wagtail 2.1
我正在尝试在 Heroku 上销毁和重新创建我的应用程序数据库。以下是我遵循的步骤:
- 创建数据库转储(成功(
- RM 所有迁移并重新创建"初始"迁移(成功(
- 运行"heroku pg:重置数据库"(成功(
- 推送新迁移和数据库转储(成功(
- 运行 'Heroku Run Python manage.py Migrate' (成功(
- 运行"Heroku Run Python manage.py Flush"(**失败**(
JVsquad$ heroku run python manage.py flush
Running python manage.py flush on ⬢ my_app... up, run.2459 (Hobby)
You have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the 'my_app_db' database,
and return each table to an empty state.
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
CommandError: Database my_app_db 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.
我的第 7 步本来是heroku run python manage.py loaddata db_dump.json
但它也失败了,因为冲洗不起作用。
请帮忙
如果没有任何效果,则可以从 heroku GUI 中删除数据库并预配新的数据库。 这将解决您的直接问题。
此外,此线程建议了一个解决方案
https://github.com/wagtail/wagtail/issues/1824
从Mysql迁移到PostgresQL后,我遇到了同样的问题。
TRUNCATE tablename CASCADE
的问题是我无法在刷新方法(即在每个测试用例方法之后运行(中设置allow_cascade=True
我覆盖了测试中使用的 Transaction 类:APITransactionTestCase
class PostgresTestCase(APITransactionTestCase):
"""
Override APITransactionTestCase class so the TRUNCATE table_name CASCADE is enabled
"""
def _fixture_teardown(self):
# Allow TRUNCATE ... CASCADE and dont emit the post_migrate signal
# when flushing only a subset of the apps
for db_name in self._databases_names(include_mirrors=False):
# Flush the database
inhibit_post_migrate = (
self.available_apps is not None or
( # Inhibit the post_migrate signal when using serialized
# rollback to avoid trying to recreate the serialized data.
self.serialized_rollback and
hasattr(connections[db_name], '_test_serialized_contents')
)
)
call_command('flush', verbosity=3, interactive=False,
database=db_name, reset_sequences=False,
allow_cascade=True,
inhibit_post_migrate=True)
现在刷新在 Postgres 中也有效。