Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#12976 closed (fixed)

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

Reported by: pczapla Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2-beta
Severity: Keywords: mysql
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

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 (2)

split_test.zip (3.8 KB) - added by pczapla 5 years ago.
A demo project that shows the problem
patch.txt (829 bytes) - added by pczapla 5 years ago.
I've attached a quick solution that fixed the problem for me.

Download all attachments as: .zip

Change History (6)

Changed 5 years ago by pczapla

A demo project that shows the problem

Changed 5 years ago by pczapla

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

comment:1 Changed 5 years ago by pczapla

  • Has patch set
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset

comment:2 Changed 5 years ago by jacob

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 5 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(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.

comment:4 Changed 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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