据我所知,运行时 $heroku 运行 python manage.py migrate
它从 models.py 创建所有表。但我的输出看起来不同:该表没有创建,甚至没有提及。
Operations to perform:
Apply all migrations: findCharge
Running migrations:
Applying findCharge.0001_initial... OK
Applying findCharge.0002_auto_20161124_1729... OK
Applying findCharge.0003_auto_20161124_1955... OK
Applying findCharge.0004_chargepoints_description... OK
无论如何,当我打电话时
$ heroku pg:psql and then ONYX=> \dt
看起来表已创建,并且“findCharge_chargepoints”位于关系列表中。
…
public | findCharge_chargepoints | table | owner_name
…
但是当我输入时
ONYX=> SELECT * FROM findCharge_chargepoints;
ERROR: relation "findcharge_chargepoints" does not exist
我试图在没有应用程序名称的情况下运行“python manage.py migrate”,但结果是相同的。在推送到 git 之前,我在本地计算机上运行“makemigrations”。我还能够创建 super 用户,我可以打开 https://my-app-name.herokuapp.com/admin并向数据库添加一些数据,但我的应用程序看不到这些数据。
有什么建议吗?我已经坚持了 3 天,所以我将感谢任何帮助。
附注我使用带有 postgis 扩展的heroku postgresql hobby-basic。
附注
settings.py 中的数据库设置:
DATABASES = {
'default':{
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'charging_points',
'USER': 'postgres',
'PASSWORD': 'XXX',
}
}
在文件末尾
import dj_database_url
DATABASES['default'] = dj_database_url.config()
DATABASES['default']['ENGINE'] = "django.contrib.gis.db.backends.postgis"
最佳答案
我想我找到了解决方案或一种解决方案。该表已创建,但要访问它,我必须使用双引号:
select * from "findCharge_chargepoints";
我没想到会这样,因为由 migrate 创建的其他表(如 auth_user、auth_group 等)根本不需要任何 qoutes。
关于python - Heroku + Django migrate 命令不会创建任何表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40818062/