Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django sqlmigrate not showing raw sql

Tags:

python

django

I tried to get the raw sql from Django migrate file.

I took the following steps:

$ python manage.py makemigrations

$ python manage.py sqlmigrate app_name 0001

and raw sql command should display, but the result only contains:

BEGIN;
--
-- Create model User
--
--
-- Create model Config
--
COMMIT;

How to get the raw sql from sqlmigrate?

like image 333
hugo2121 Avatar asked Sep 16 '26 16:09

hugo2121


1 Answers

I read the source code of sqlmigrate and found that add DB name for migrate may work.

So the working version would be:

$ python manage.py sqlmigrate app_name 0001 --database=db_name

The source code is here: https://github.com/django/django/blob/master/django/core/management/commands/migrate.py

like image 64
hugo2121 Avatar answered Sep 18 '26 06:09

hugo2121



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!