如何从SQLite迁移到Postgres [英] How to migrate from sqlite to postgres

查看:110
本文介绍了如何从SQLite迁移到Postgres的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在heroku上已经有了一个django项目。我现在想将数据库从sqllite迁移到postgres,因为存在一些与heroku有关的问题,例如当我设置 DEBUG = True 时,该站点运行没有任何问题,但我将 DEBUG 设置为 False ,我会收到服务器错误500。我很难找到任何有效的解决方案,所以我ve决定搬到Postgres。因此,我将 settings.py 文件更改为使用默认数据库作为postgres。我不知道此文件中有关生产设置的任何其他更改。此外,我在Windows计算机上,已经安装了postgres,还安装了 psycopg2 库。已经在postgres中手动创建了数据库。

I already have a django project live on heroku. I am now wanting to migrate the database from sqllite to postgres because of some issues regarding heroku like when I set DEBUG=True, the site runs without any issues but as soon as I set DEBUG to False, I get server error 500. I'd hard time finding any working solution, so I've decided to move to postgres. So, I have changed my settings.py file to have default db as postgres. I don't know about any other change in this file regarding the production settings.Also, I'm on windows machine and have installed postgres, also installed the psycopg2 library.I have created the db manually in postgres.

我面临的问题是,一旦运行 makemigrations 命令,它将创建一个sqlite数据库。为什么会发生这种情况?

The issue I'm facing is, as soon as I run makemigrations command, it creates an sqlite db. Why does this happen?

推荐答案

运行 python manage.py makemigrations 您需要运行 python manage.py migration ,将数据应用于新数据库。

After you have run python manage.py makemigrations you need to run python manage.py migrate to apply the data to the new database.

这篇关于如何从SQLite迁移到Postgres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆