Django

Code

Ticket #12976 (closed: fixed)

Opened 5 months ago

Last modified 5 months ago

manage.py sqlflush issues to many 'ALTER' when using multiple mysql databases.

Reported by: pczapla Assigned to: nobody
Milestone: 1.2 Component: Database layer (models, ORM)
Version: 1.2-beta Keywords: mysql
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 0

Description

In a brief when I have two databases with different sets of models the sqlflush statement output ALTER TABLE .. AUTO_INCREMENT = 1; for all tables in an application. The TRUNCATE commands are issued for the right tables.

The problem is quite importan for us as it breaks the test command.

I've created an application that demonstrate the problem. It has two databases: 'default' and 'second' and two models: 'ModelOnTheDefaultDB', 'ModelOnTheSecondDB'.

Here is how the output of syncdb and sqlflush looks like:

$ python manage.py syncdb
Creating table test_app_modelonthedefaultdb

$ python manage.py syncdb --database='second'
Creating table test_app_modelontheseconddb

$ python manage.py sqlflush
BEGIN;
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE `test_app_modelonthedefaultdb`;
SET FOREIGN_KEY_CHECKS = 1;
ALTER TABLE `test_app_modelonthedefaultdb` AUTO_INCREMENT = 1;
ALTER TABLE `test_app_modelontheseconddb` AUTO_INCREMENT = 1;  -- This alter table should not be here
COMMIT;

$ python manage.py sqlflush --database='second'
BEGIN;
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE `test_app_modelontheseconddb`;
SET FOREIGN_KEY_CHECKS = 1;
ALTER TABLE `test_app_modelonthedefaultdb` AUTO_INCREMENT = 1; -- This alter table should not be here
ALTER TABLE `test_app_modelontheseconddb` AUTO_INCREMENT = 1; 
COMMIT;

Attachments

split_test.zip (3.8 kB) - added by pczapla on 02/26/10 05:48:25.
A demo project that shows the problem
patch.txt (0.8 kB) - added by pczapla on 03/01/10 11:39:11.
I've attached a quick solution that fixed the problem for me.

Change History

02/26/10 05:48:25 changed by pczapla

  • attachment split_test.zip added.

A demo project that shows the problem

03/01/10 11:39:11 changed by pczapla

  • attachment patch.txt added.

I've attached a quick solution that fixed the problem for me.

03/01/10 11:39:51 changed by pczapla

  • needs_better_patch changed.
  • has_patch set to 1.
  • needs_tests set to 1.
  • needs_docs changed.

03/01/10 17:02:01 changed by jacob

  • stage changed from Unreviewed to Accepted.

03/10/10 07:43:23 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(In [12753]) Fixed #12976 -- Fixed the sequence reset commands issued by sqlflush in a multidb setup. To achieve this, database introspection was modified to utilize routing information to determine if a model should be available. Thanks to pczapla for the report.


Add/Change #12976 (manage.py sqlflush issues to many 'ALTER' when using multiple mysql databases.)




Change Properties
Action