2016-11-26 45 views
0

据我所知运行 $ Heroku的执行python manage.py迁移的Heroku + Django的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 

我试图不应用程序名称运行“蟒蛇manage.py迁移”,但结果是一样的。在推送到git之前,我在本地机器上运行“makemigrations”。我也能创建超级用户,我可以打开https://my-app-name.herokuapp.com/admin并添加一些数据到数据库,但我的应用程序不会看到这些数据。

有什么建议吗?我现在坚持3天,所以我会很感激任何帮助。

P.S.我使用heroku postgresql hobby-basic和postgis扩展。

P.P.S.从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" 
+0

可以显示数据库设置吗? –

+0

如果它不使用默认的'公共'模式,那么你可能还必须提供完整的'schema.table'路径。 – shongololo

+0

丹尼尔罗斯曼,我刚刚添加这个信息的问题,如果它可以帮助。 – sHalnes

回答

1

我想我找到了解决办法或者说是一种解决方案的结束。饭桌上,但去访问它创建的我必须使用双引号:

select * from "findCharge_chargepoints"; 

我没想到它会通过迁移创建的其它表(如AUTH_USER,auth_group等)不需要任何qoutes。

+0

那是因为你有一个大写字母...... ** C **中的“C”。如果你不用双引号,它可能会查找'findcharge_chargepoints'(注意小写的“c”负责)。当你把双引号括起来时,你可以说明你的表名和大写/小写。 – Sharky

+0

谢谢@Sharky,现在我明白了。 – sHalnes

+0

为了澄清,因为行为对我来说有点不明显:PostgreSQL标识符在技术上是区分大小写的,但是当在DML或DDL中使用_unquoted_标识符时,PostgreSQL隐式地降低了它的情况。因此,'select * from AUTH_USER'被处理为'select * from auth_user'并且工作正常,因为表名是“auth_user”(而不是“AUTH_USER”)。但是,如果您从'AUTH_USER''选择*,则查询将失败。所以,无论是用引用标识符创建你的'findCharge_chargepoints'表还是显式的。 – bimsapi