I have a MySQL database previously used with a Laravel backend. I'm now transitioning to Django and have created a new Django project while keeping the database schema unchanged, with only a few naming improvements for clarity. However, I'm encountering an issue when connecting to the previous database. When running migrations, it creates new empty tables in the database instead of using the existing ones. I don't want to lose any existing data. I need help resolving this issue.
#How to integrate existing MySQL database into a new django project?
11 messages · Page 1 of 1 (latest)
see "inspectdb" and "legacy database" in official docs
that didn't work as the tables already existed in my db so when i mapped the models with corresponding tables and try to run migrations then got at a error that table already exists
What didn't work? Whole point of what I mentioned is that you have tables already
So it wouldn't work if you hadn't
You can migrate tables to model files usingpython manage.py incpectdbinstead of migrate .
Changing the table structure can modify the database by executing the above command.
Inspectdb doesn't migrate the tables automatically, you need to copy its output into your model.py file or run python manage.py inspectdb > models.py to port it over. ( Use >> if file already exists, or has other tables in it )
https://docs.djangoproject.com/en/5.0/howto/legacy-databases/
Hi,
I am trying to link mysql database to my django project. I installed XAMPP and created a mysql database from that side. Whenever I do migrations, it just creates an sql lite db.
I am unable to attach the picture of the issue here. How do i resolve this error ?
Thank you for your assistance.
You've already asked this elsewhere, please do not spam, thank you!
Yes