How to migrate SQLite Database to MYSQL in Django
How to migrate SQLite Database to MYSQL in Django
I am struggling in migrating SQLite to MYSQL in django and searching for best way to do so. If anyone knows then please guide the way to do so.
Re: How to migrate SQLite Database to MYSQL in Django
Great Question which is addressed here. Before giving answer let me proceed with knowing you how python programs are interfaced with the databases.
Database Driver
PostgreSQL psycopg2 module
MYSQL MySQL-python or mysql-client
Now It is very easy if you have understand the above written concept. You need to migrate SQLite database to MYSQL so use driver mysqlclient. You can install it using pip. Please type below command
Great you are done with the step 1. Now create name of database in the mysql by login mysql with the username and password.
If some one donot know how to login to mysql, then donot worry. Please type the below command in the terminal
Enter the password which one have set during mysql installation.
It is the time to create database. When you enter mysql through terminal, please enter the below command
It is the time to grant privileges for the database created for the user.
Please flush the PRIVILEGES
Quit from database in the terminal using the below command
Go to settings.py inside the created django project and edit the below lines
Orginal code
Modified Code
Thanks and With Regards
http://www.aisangam.com/
If not, then the answer is through drivers. Let me write down belowDo you know how python programs are interfacing with the databases.
Database Driver
PostgreSQL psycopg2 module
MYSQL MySQL-python or mysql-client
Now It is very easy if you have understand the above written concept. You need to migrate SQLite database to MYSQL so use driver mysqlclient. You can install it using pip. Please type below command
Code: Select all
pip install mysqlclient
If some one donot know how to login to mysql, then donot worry. Please type the below command in the terminal
Code: Select all
mysql -u root -p
It is the time to create database. When you enter mysql through terminal, please enter the below command
Code: Select all
CREATE DATABASE **your_project_name** CHARACTER SET UTF8;
Code: Select all
GRANT ALL PRIVILEGES ON your_project_name.* TO your_username@localhost;
Code: Select all
FLUSH PRIVILEGES;
Code: Select all
QUIT
Orginal code
Code: Select all
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
Code: Select all
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '', # Name of database
'USER': '', # user may be root or anything else
'PASSWORD': '', password you login for mysql
'HOST': 'localhost',
'PORT': '',
}
}
http://www.aisangam.com/