Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#15926 closed New feature (fixed)

Option to not load initial fixtures during syncdb

Reported by: msiedlarek Owned by: msiedlarek
Component: Core (Management commands) Version: master
Severity: Normal Keywords: management syncdb options fixtures
Cc: msiedlarek, albrecht.andi@…, Jonathan Paugh Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: yes UI/UX: no

Description

There are some situation in which you may want to prevent automatic loading of initial fixtures by syncdb management command. One example is when you want to create a database schema and fill it with data from the other database. If there were initial fixtures loaded in both databases there probably would be some primary key conflicts raised.

There is a stealth option for that, called load_initial_data, and used by testing setup, by I believe it's not fair to take away from user such a useful one.

Attachments (5)

ticket15926.patch (1.3 KB) - added by msiedlarek 5 years ago.
Patch
ticket15926-with-flush.patch (2.8 KB) - added by Jonathan Paugh 5 years ago.
Reincarnation of patch supporting the flush command as well
ticket15926-doc.patch (943 bytes) - added by Jonathan Paugh 5 years ago.
Documentation for the (with-flush) patch
15926.patch (3.4 KB) - added by vlinhart 4 years ago.
15926_test.patch (1.8 KB) - added by vlinhart 4 years ago.

Download all attachments as: .zip

Change History (20)

Changed 5 years ago by msiedlarek

Attachment: ticket15926.patch added

Patch

comment:1 Changed 5 years ago by msiedlarek

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

comment:2 Changed 5 years ago by Aymeric Augustin

Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedDesign decision needed

Why not, but it sounds like you're misusing the initial_data fixtures.

In my understanding, they exist for data that will always be in your database and will not change. For example, you have some fixed categories used by M2M fields in other models, so you create a model for them and hardcode the list in a fixture.

comment:3 Changed 5 years ago by msiedlarek

I see your point, but as I said -- when you're using django-admin fixtures and syncdb everything should be ok, but when using some Django-independent database management utilities existence of initial data in freshly created database schema can cost you some trouble. In fact -- I'm facing this problem right now. Besides -- this is nice, simple feature which doesn't complicate anything that much.

comment:4 Changed 5 years ago by Aymeric Augustin

#15985 was a duplicate.

comment:5 Changed 5 years ago by Andi Albrecht

Cc: albrecht.andi@… added
UI/UX: unset

comment:6 Changed 5 years ago by Aymeric Augustin

Easy pickings: set
Triage Stage: Design decision neededAccepted

comment:7 Changed 5 years ago by Aymeric Augustin

#9549 is related.

comment:8 Changed 5 years ago by Jonathan Paugh

Patch needs improvement: set

What about the flush command? This change should be included there, too. I'm marking the patch as 'needs improvement.' By the way, I think this feature can be very useful, for development anyway. Whenever I change my models and need to resync, I often want to quickly verify the model without having to update my initial data---sometimes this is necessary anyway, but not always.

Changed 5 years ago by Jonathan Paugh

Reincarnation of patch supporting the flush command as well

Changed 5 years ago by Jonathan Paugh

Attachment: ticket15926-doc.patch added

Documentation for the (with-flush) patch

comment:9 Changed 5 years ago by Jonathan Paugh

Cc: Jonathan Paugh added
Needs documentation: unset
Patch needs improvement: unset

I think with the new patch and the documentation patch, this is ready for review by a core dev. Sorry for stealing your thunder, msiedlarek.

comment:10 Changed 5 years ago by Jonathan Paugh

Version: 1.3SVN

I made my patches against the SVN (git) tip, so I changed the version. I'm guessing that's the protocol.

comment:11 Changed 5 years ago by Aymeric Augustin

Patch needs improvement: set

Could you:

  • consolidate all the changes in a single diff file?
  • ensure you're indenting consistently with the surrounding code?

Also, this still needs tests.

comment:12 Changed 4 years ago by vlinhart

I've consolidated the three pathes into one and are now up-todate with the current head. There is another patch which contains tests.

Changed 4 years ago by vlinhart

Attachment: 15926.patch added

Changed 4 years ago by vlinhart

Attachment: 15926_test.patch added

comment:13 Changed 4 years ago by Honza Kral <honza.kral@…>

Resolution: fixed
Status: newclosed

In [fedac99c859c626544d38fc0ea07207ef3fd101a]:

Fixed #15926 -- Added option --no-initial-data to syncdb and flush.

Thanks msiedlarek, jpaugh64 and vlinhart!

comment:14 Changed 4 years ago by Claude Paroz <claude@…>

In [f0664dc8ae541b21e3cf421725e7933a9b3a799e]:

Made TestNoInitialDataLoading pass with MySQL (Refs #15926)

comment:15 Changed 4 years ago by Claude Paroz <claude@…>

In [2c57809a560cb67c79b9e8a77cc713e8a2424c8e]:

Prevented TestNoInitialDataLoading to pollute other tests (Refs #15926)

Tests were still failing with MySQL. It seems a rollback is solving
the issue.

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