How to switch from MySQL to Postgre on Heroku - mysql

I want to host a django project on heroku. Locally, I developed it using MySQL database. And I have also pushed it to heroku but I get an Error message whenever I run heroku open command on command prompt. The error message is Can't connect to local MySQL server through socket. Though I'm a newbie in using databases, the way I understand the error is that heroku can't connect to local MySQL server which I'm using for local development. I don't want to connect to a remote MySQL database, instead, I want to connect to Postgre database just as heroku recommended.
Being a newbie in the use of database, I don't know the best way to migrate to Postgre or how to add MySQL in my project to .gitignore. Is it possible for me to start running Postgre on heroku while MySQL isn't added to . gitignore and is still the database in settings.py? Must I clear MySQL database or add it to gitignore before I can use Postgre?

PostgreSQL settings for Heroku:
Please install dj_database_url using below command:
pip install dj-database-url
In settings.py , import dj_database_url and add below settings at the end of the file:
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
Done !! Now, deploy again to Heroku.

Related

How to reconnect from workbench to heroku app?

I have made a React+Node application with MySQL database. I'm using Heroku to deploy my application, and have done so successfully. However, I'm having problems with using my database on Heroku. Locally I'm using XAMPP and phpmyadmin for all database work.
In Heroku, I've used a clearDB add on to support MySQL and have gotten all necessary credentials in the format:
mysql://DB_USERNAME:DB_PASSWORD#BD_HOST/DB_DATABASE?reconnect=true
I've used MySQL Workbench and have created a database using the above supplied host name, username, password and have successfully connected the database to the app. But after a while i changed (on PhpMyadmin) the database structure and i deleted the connection from workbench panel. I tryied to make a new connection with the same Config Vars but the workbench send me an error of "Unknown Database nameOfDatabase".
There is something i missing? there is anything i have to do to delete the old connection for the new one to work?
thanks!

Issue with setting tables remote ClearDB (heroku) database

I'm trying to migrate my app from a Cloud9 IDE to the Heroku platform. I'm able to serve up the page no problem but the page isn't loading any of the info that was supposedly migrated over. I'm not seeing any error messages, nor do I know how to check if the tables were created properly in ClearDB.
How do I make sure my tables were created properly and the data was loaded?
The following steps were taken:
-Get remote MySQL setup on Heroku with the ClearDB Ignite variant
-Change the database connection in my Express server to the credentials of my Heroku app (if/else that looks if CLEARDB_DATABASE_URL exists and connects using the Heroku app url)
-Dumped the database tables into a file and ran the file on the remote db:
-- mysqldump -uroot --no-data > tables.sql
--mysql -h"us-cdbr-iron-east-04.cleardb.net" database < tables.sql
Ok. I figured it out. It looks like I exported the just the tables, not the entire database with values. I did a mysqldump for the entire database and then pushed it to heroku and everything appeared.

How to import a MySQL db to OpenShift?

I've been working on a JSP project and now I want to host in on Openshift. Everything is set up except for the database. I already added MySQL 5.5 cartridge and phpMyAdmin 4.0 and I edited the credentials in my project as shown below. But how can I upload my database data to the application?
Constants in my project
Apparently, the key was to replace the variables in the DB URL with the openshift variables.
To upload your data into your database you could use a tool to manage you tables (for example Squirrel-SQL). To connect it with your openshift-database enable the port-forwarding through your rhc console so you can access the database as it would be a local one and connect to it through squirrel. (you cannot connect direcly to the remote database from openshift - only with port-forwarding)
rhc <app-name> port-forward

Migrating a local mysql database to heroku postgres from a cakephp application

Hi I'm trying to migrate a database that was created with cakePHP on a local MYSQL database. I know that in rails the solution is to install the postgres gem that will handle the migration, but I'm wondering more specifically about cakePHP.
I've generated a sqldump of the mysql database using the solution here:
http://book.cakephp.org/2.0/en/console-and-shells/schema-management-and-migrations.html
I've also installed postgres locally onto my machine and am able to connect to my remote empty HEROKU database from the command line by using heroku pg:psql
However, if I run the SQL dump file directly in the console I get an error called SSL SYSCALL error: Software caused connection abort. This apparently is because as a DEV / Free database account you are restricted from entering SQL commands directly.
So, that would suggest that I would have to go and use something like
heroku db:push localdatabase herokudatabase
But that produces the error Sequel::AdapterNotFound -> LoadError: 193: not a valid Win32 application
Any ideas how I might manage this migration, bearing in mind that as it's a CakePHP application I do not have the option of just installing a PostGres gem?
Thanks for any direction, or thoughts.
You almost certainly want to install Postgres locally on your machine, and get your database and code working correctly there. Once it's set up, it's easy to do a dump of your Postgres database and upload to Heroku.

How to push my Mysql database to heroku via mysql workbench?

I have created cleardb on heroku, I want to push my mysql database on local disk to heroku. I have mysql workbench installed. How can i push it to heroku ?
look at the output of heroku config - you will see an key called CLEARDB_DATABASE_URL this is the connection string your application uses to talk to your database.
You can take this URL and break it up into it's constituent parts to get a username, password, host, port and database name which you can use in a connection via mysql workbench.
See https://devcenter.heroku.com/articles/cleardb for further reference.
If u want to just push your database, use console, it's simple:
heroku db:push