“没有这样的表”在django syncdb通过后,Heroku出现错误 [英] "no such table" error on Heroku after django syncdb passed
问题描述
我正在尝试将我的Django应用程序部署到Heroku。迁移在我的本地Git。当我尝试:
I'm trying to deploy my Django application to Heroku. The migrations are in my local Git. When I try:
git push heroku master
heroku run python manage.py syncdb
它应用迁移,并且还允许我创建超级用户,这是我成功的。现在应用程序已启动并运行,但是当我尝试登录Django管理员时,它会抛出:
It applies the migrations and also promts me to create superuser, which I successfully do. Now the application is up and running, however when I try to log into the Django admin it's throwing:
OperationalError no such table: user_user
当我尝试
heroku run python manage.py makemigrations
heroku run python manage.py migrate
heroku run python manage.py createsuperuser
它应用所有迁移,但无法创建超级用户投掷:
It applies all migrations, but fails to create superuser throwing:
django.db.utils.OperationalError: no such table: user_user
无论如何,我无法拥有数据库设置和迁移在Heroku。
Either way I can not have my database set up and migrated on Heroku.
我的数据库设置是:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
我的用户模型是: / p>
My user model is:
class User(AbstractUser):
rating = models.PositiveIntegerField(default=settings.DEFAULT_USER_RATING)
Django版本是1.7.1。
Django version is 1.7.1.
如何获取在Heroku上创建的数据库表?
How do I get my database tables created on Heroku?
推荐答案
您不能在Heroku上使用sqlite3。
You must not use sqlite3 on Heroku.
sqlite将数据库作为文件存储在磁盘上。但是,在一个Heroku Dyno中的文件系统并不是持久的,而是在dynos之间不共享。所以,当你执行 heroku运行python manage.py migrate
时,Heroku用一个空白数据库旋转一个新的动态库,运行迁移,然后删除dyno和数据库。运行您的站点的dyno不受影响,永远不会被迁移。
sqlite stores the database as a file on disk. But the filesystem in a Heroku dyno is not persistent, and is not shared between dynos. So, when you do heroku run python manage.py migrate
, Heroku spins up a new dyno with a blank database, runs the migrations, then deletes the dyno and the database. The dyno that's running your site is unaffected, and never gets migrated.
您必须使用Heroku数据库附加组件之一。 Postgres有一个免费的层级。您应该使用dj-database-url库从Heroku设置的环境变量动态设置数据库设置。
You must use one of the Heroku database add-ons. There is a free tier for Postgres. You should use the dj-database-url library to set your database settings dynamically from the environment variables which Heroku sets.
同样,由于同样的原因, code> manage.py makemigrations 本地,将结果提交到git,然后推送到Heroku。
Also, for the same reason, you must do manage.py makemigrations
locally, commit the result to git, then push to Heroku.
这篇关于“没有这样的表”在django syncdb通过后,Heroku出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!