My project is built in Python Django which I have set up on Digital Ocean Cloud but it has inbuilt DBSQLITE database, I want to connect mysql with my database, when I connected mysql and loaded the data, I got empty tables, the data did not come. Please tell me step by step steps
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Hey!
Are you using the DigitalOcean App Platform? If this is the case, the best approach here would be to use a managed MySQL cluster.
Using SQLite with the App Platform is not recommended as the App Platform has ephemeral storage, meaning that any data you store on the App Platform itself locally, will be lost after each redeployment.
To set up MySQL in your Python Django project on DigitalOcean, and resolve the issue of empty tables when migrating, follow these steps:
Create a MySQL Cluster:
Install Django MySQL Adapter:
pip install mysqlclient
Update settings.py
:
Open your Django project’s settings.py
file and update the DATABASES
setting:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'your_database_name',
'USER': 'your_mysql_user',
'PASSWORD': 'your_mysql_password',
'HOST': 'your_mysql_host', # e.g., 'db-mysql-nyc3-12345-do-user-67890-0.b.db.ondigitalocean.com'
'PORT': 'your_mysql_port', # e.g., '25060'
}
}
Replace your_database_name
, your_mysql_user
, your_mysql_password
, your_mysql_host
, and your_mysql_port
with the details from your DigitalOcean Managed MySQL Database.
After that redeploy your project to the App Platform.
Let me know how it goes!
Best,
Bobby
Heya @zappcodeacademy,
The data you have in your SQLLITE db will not automatically migrate over to the MySQL.
Yes, you can run your migrations to create the structure of your DB in MySQL however you’ll need to find another way to dump the data from your SQLLITE to MySQL.
Let’s first make sure you ahve the proper stuff in your settings.py file:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'myproject',
'USER': 'myprojectuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
}
}
python manage.py makemigrations python manage.py migrate
python manage.py dumpdata > datadump.json
python manage.py migrate --run-syncdb
python manage.py loaddata datadump.json
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.