【问题标题】:ProgrammingError: relation "account_account" does not existProgrammingError:关系“account_account”不存在
【发布时间】:2020-03-06 13:09:36
【问题描述】:

我使用 django-user-accounts==2.1.0 改进了注册表单。在我的本地服务器上一切正常,但在 heroku 服务器上我看到以下错误:

Django Version: 2.2.6
Exception Type: ProgrammingError
Exception Value:    
relation "account_account" does not exist
LINE 1: ...nt"."timezone", "account_account"."language" FROM "account_a...
Exception Location: /app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py in _execute, line 84

我删除了数据库并再次makemigrations/migrate,它没有帮助。

我的 settings.py 的相关部分:

import dj_database_url
db_config = dj_database_url.config()
if db_config:
    DATABASES['default'] =  db_config

迁移命令的输出:

Operations to perform:
  Apply all migrations: account, admin, auth, contenttypes, sessions, my_apps, sites
Running migrations:
  No migrations to apply.

DATABASE_URL 也定义了:

heroku config
=== Config Vars
DATABASE_URL:        postgres://bvki...longrul

这里我尝试获取表“account_account”:

>manage.py dbshell
SQLite version 3.30.1 2019-10-10 20:19:45
sqlite> SELECT * FROM "account_account";
1||1|lt
2||2|en

在sqlite中“account_account”存在!

但在此命令的输出中不是迁移“帐户”!

>heroku run python manage.py migrate
Running python manage.py migrate on ⬢ my-app... up, run.5012 (Free)
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions, my_app
Running migrations:
  No migrations to apply.
  Your models have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

【问题讨论】:

    标签: django django-authentication


    【解决方案1】:

    它看起来不像你的 makemigrations / migrate 运行,因为这告诉你该表不存在。

    (1) 运行 makemigrationsmigrate,并确保您使用正确的设置运行以在 Heroku 服务器上运行它。 (2) 使用您对 Heroku 服务器的设置运行python manage.py dbshell,并查看存在的表(PostgreSQL 中的\dt)。 account_account 存在吗?

    【讨论】:

    • 感谢您的回复!我补充了我的答案,并提供了有关您的答案的更多信息。 Сan你更详细地描述(2)点?如何使用 Heroku 服务器的设置来实现?
    • 嘿@lleviy 你解决了吗?我遇到了类似的问题。
    • @Dimanjan 是的,我需要在 Heroku 服务器上进行迁移,而不是在本地服务器上进行。在此之前,我在 heroku 服务器上的数据库是空的。这个命令解决了我的问题:heroku run python manage.py make migrations
    猜你喜欢
    • 2018-10-25
    • 2013-05-06
    • 2023-03-14
    • 1970-01-01
    • 2018-05-23
    • 2016-05-01
    • 2016-04-11
    • 2016-10-01
    • 2017-06-26
    相关资源
    最近更新 更多