内部版本:Heroku Python服务器,Postgresql 10.4,Django 2,Wagtail 2.1
我正在尝试从本质上销毁并重新创建我的应用程序数据库。这是我遵循的步骤:
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
,但也失败了,因为冲洗不起作用。
请帮助
答案 0 :(得分:0)
如果没有任何效果,则可以从heroku GUI删除数据库并置备新数据库。这样可以解决您眼前的问题。
此外,该主题提出了解决方案
答案 1 :(得分:0)
从Mysql迁移到PostgresQL之后,我遇到了同样的问题。
TRUNCATE tablename CASCADE
的问题在于我无法在flush方法(在每个测试用例方法之后运行)中设置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中使用。