[Django 1.8.6] How to dump sql from models

57 views
Skip to first unread message

marcin....@gmail.com

unread,
Nov 16, 2015, 7:14:17 PM11/16/15
to Django users
Hi!

After upgrade from 1.5 to 1.8.6 I'm trying to dump sql from models.
I'm not using django migrations, and my db_router does not allow for migrations.

Every "sql*" management command gives me nothing (empty output), where I'm expecting generated SQL.

  1. How can I dump tables and indices creation sql from my models with new Django?
  2. What was wrong with old-style method?

Kind Regards,
Marcin

Mike Dewhirst

unread,
Nov 16, 2015, 8:01:36 PM11/16/15
to django...@googlegroups.com
On 17/11/2015 11:14 AM, marcin....@gmail.com wrote:
> Hi!
>
> After upgrade from 1.5 to 1.8.6 I'm trying to dump sql from models.
> I'm not using django migrations, and my db_router does not allow for
> migrations.
>

Try this ...

1. Rename all the migrations directories if they exist

2. $~python manage.py sql [appname1] [appname2] > project_[date].sql

3. Restore the directory names so they don't get recreated

Good luck

> Every "sql*" management command gives me nothing (empty output), where
> I'm expecting generated SQL.
>
> 1. How can I dump tables and indices creation sql from my models with
> new Django?
> 2. What was wrong with old-style method?
>
>
> Kind Regards,
> Marcin
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6f401bdc-dd91-48b4-b8f8-5206db588d76%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/6f401bdc-dd91-48b4-b8f8-5206db588d76%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Tim Graham

unread,
Nov 16, 2015, 8:04:27 PM11/16/15
to Django users
For Django 1.9+, I don't think there's a built-in way to do so. Until that feature makes its way into Django (if it ever does), it might not be difficult to reimplement those commands to the extent that you need them as a third-party app. See https://groups.google.com/d/topic/django-developers/h92CcblbYfk/discussion for discussion and a start.


On Monday, November 16, 2015 at 8:01:36 PM UTC-5, Mike Dewhirst wrote:
On 17/11/2015 11:14 AM, marcin....@gmail.com wrote:
> Hi!
>
> After upgrade from 1.5 to 1.8.6 I'm trying to dump sql from models.
> I'm not using django migrations, and my db_router does not allow for
> migrations.
>

Try this ...

1. Rename all the migrations directories if they exist

2. $~python manage.py sql [appname1] [appname2] > project_[date].sql

3. Restore the directory names so they don't get recreated

Good luck

> Every "sql*" management command gives me nothing (empty output), where
> I'm expecting generated SQL.
>
>  1. How can I dump tables and indices creation sql from my models with
>     new Django?
>  2. What was wrong with old-style method?
>
>
> Kind Regards,
> Marcin
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com

marcin....@gmail.com

unread,
Nov 16, 2015, 8:33:09 PM11/16/15
to Django users
Mike, thanks.  I have no migration directories, so assuming that it would not help.

Tim, also thanks. I've checked that django-dev discussion, but no updates here.
I don't want to discuss again and again about kicking out useful tools.
 
It looks like reimplementing old commands is the only way... Thanks.

Marcin

Mike Dewhirst

unread,
Nov 16, 2015, 8:39:48 PM11/16/15
to django...@googlegroups.com
On 17/11/2015 12:33 PM, marcin....@gmail.com wrote:
> Mike, thanks. Â I have no migration directories, so assuming that it
> would not help.

I just checked and I tested that on 1.8.5

So maybe step 0 is to downgrade and step 4 is to upgrade again.

Cheers

Mike


>
> Tim, also thanks. I've checked that django-dev discussion, but no
> updates here.
> I don't want to discuss again and again about kicking out useful tools.
> Â
> It looks like reimplementing old commands is the only way... Thanks.
>
> Marcin
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4b2803b1-e1aa-4230-a1ee-764751fce16f%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4b2803b1-e1aa-4230-a1ee-764751fce16f%40googlegroups.com?utm_medium=email&utm_source=footer>.

Mike Dewhirst

unread,
Nov 16, 2015, 11:13:21 PM11/16/15
to django...@googlegroups.com
On 17/11/2015 12:33 PM, marcin....@gmail.com wrote:
> I have no migration directories, so assuming that it would not help

It has just occurred to me that I don't have any unmanaged apps. Maybe
that is why it worked for me? I seem to remember you need to mark apps
as unmanaged to switch off migrations.

Mike
Reply all
Reply to author
Forward
0 new messages