Django
in this tutorial, we will take a django app backed by mysql and will convert mysql database to postgres database. this is useful if we are deploying our app toherokubecauseherokuuses standardpostgres
Let's assume that you have a django app running with MySQL and you want to convert this to Postgres.
1) Install dependenicies:
$ pip install psycopg2$ pip install py-mysql2pgsql
2) Create Postgres database:
postgres@agiliq-Inspiron-N5010:~$ psqlpsql (9.1.11)Type "help" for help.postgres=# create database my_database;CREATE DATABASEpostgres=#
3) Run:
$ py-mysql2pgsql
At initial run this command creates a file namedmysql2pgsql.ymlhaving the below info:
mysql:hostname: localhostport: 3306socket: /tmp/mysql.sockusername: foopassword: bardatabase: your_database_namecompress: falsedestination:postgres:hostname: localhostport: 5432username: foopassword: bardatabase: your_database_name
Update the above configuration file with appropriate database credentials for both 'MySQL' andPostgres.
4) Run:
$ py-mysql2pgsql -v -f mysql2pgsql.yml
The above command will transfer the data fromMySQLdatabase toPostgres.
Note:
Integrityerrors, but no worries it can be fixed. :)5) Be sure to update your databasesettings.pyfile:
DATABASES = {"default": { "ENGINE": "django.db.backends.postgresql_psycopg2", "NAME": "your_database_name", "USER": "your_username", "PASSWORD": "your_password", "HOST": "localhost", "PORT": "5432",}}6) Verify the correctness by adding some data to your existing database(Postgres).
You can read all ofmanjunath's post, andfollow manjunath on Twitter
Can we help you build amazing apps?Contact us today.
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号