Opened 10 years ago

Closed 10 years ago

#23102 closed Cleanup/optimization (fixed)

Document change in manage.py sql* --database behavior in 1.7

Reported by: manuel.gysin@… Owned by: Gabriel Muñumel
Component: Documentation Version: 1.7-rc-1
Severity: Normal Keywords:
Cc: areski@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,

If you set DATABASE_ROUTERS in settings.py, none of the sql-management commands are working:

[root@dgweb Demo]# python manage.py sqlall SampleModel
[root@dgweb Demo]#
[root@dgweb Demo]# python manage.py sql SampleMode
[root@dgweb Demo]#

As soon DATABASE_ROUTERS is removed, things start working again:

[root@dgweb Demo]# python manage.py sqlall SampleModel
BEGIN;
CREATE TABLE "SampleModel_location" (
    "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
    "name" varchar(50) NOT NULL
)
;

COMMIT;

Attachments (1)

SampleApp.tar.gz (2.6 KB ) - added by manuel.gysin@… 10 years ago.
SampleDemo

Download all attachments as: .zip

Change History (10)

comment:1 by Claude Paroz, 10 years ago

Resolution: needsinfo
Status: newclosed

I guess this might be related to the content of your DATABASE_ROUTERS setting. The best way to prove us the presence of a bug would be to provide a sample project where this can be reproduced.

by manuel.gysin@…, 10 years ago

Attachment: SampleApp.tar.gz added

SampleDemo

comment:2 by anonymous, 10 years ago

Resolution: needsinfo
Status: closednew

Hello

No it have nothing to do with the setting itself.
There is a different behavior between Django 1.6 and 1.7.

This gives no output, because SampleModel in the second_db.

[mgysin@localhost Demo]$ python manage.py sqlall SampleModel
[mgysin@localhost Demo]$

Adjusting the command with --database argument, get things working again:

[mgysin@localhost Demo]$ python manage.py sqlall SampleModel --database=second_db
BEGIN;
CREATE TABLE "SampleModel_location" (
    "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
    "name" varchar(50) NOT NULL
)
;

COMMIT;

I'm not sure if this is a design decision or just some side effect with Django 1.7.
But it is very confusing if you are not aware of that. Maybe something like 'Only models in the default database are used, for other databases please provide --database argument' should be printed?

I've added an demo sample with this behavior.

comment:3 by Areski Belaid, 10 years ago

It's definitely a change of behaviour in Django 1.7.

In 1.7 we read the models from router.get_migratable_models:

https://github.com/django/django/blob/master/django/core/management/sql.py#L45

in 1.6 we read the models from models.get_models:

https://github.com/django/django/blob/1.6.5/django/core/management/sql.py

I'm not sure what's the desired implementation for 1.7

comment:4 by Tim Graham, 10 years ago

Component: Core (Management commands)Documentation
Summary: SQL-Management does not work with DATABASE_ROUTERS setDocument change in manage.py sql* --database behavior in 1.7
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

The new behavior makes sense to me. I think we should clarify the documentation and add a note about it in the 1.7 release notes.

comment:5 by Gabriel Muñumel, 10 years ago

Owner: changed from nobody to Gabriel Muñumel
Status: newassigned

comment:6 by Gabriel Muñumel, 10 years ago

I made the change in release notes for 1.7 version but I cannot get the commit working. I followed the documentation, but on commit I got an error: fatal: unable to access 'https://github.com/django/django.git/': The requested URL returned error: 403. I'm new on this, :(

Version 0, edited 10 years ago by Gabriel Muñumel (next)

comment:7 by Areski Belaid, 10 years ago

Cc: areski@… added

comment:8 by Tim Graham, 10 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

Don't forget to check the "Has patch" flag so the ticket appears in the review queue. I'll review and commit this now. Thanks.

comment:9 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 2077bbe3fefb58eadfde0f2f36af13a0f1d3704a:

[1.7.x] Fixed #23102 -- Documented that sql* commands now respect allow_migrate().

Backport of 0af593dbe5 from master

Note: See TracTickets for help on using tickets.
Back to Top