Opened 4 years ago

Closed 3 years ago

Last modified 3 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@…, jpaugh64 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 4 years ago.
Patch
ticket15926-with-flush.patch (2.8 KB) - added by jpaugh64 3 years ago.
Reincarnation of patch supporting the flush command as well
ticket15926-doc.patch (943 bytes) - added by jpaugh64 3 years ago.
Documentation for the (with-flush) patch
15926.patch (3.4 KB) - added by vlinhart 3 years ago.
15926_test.patch (1.8 KB) - added by vlinhart 3 years ago.

Download all attachments as: .zip

Change History (20)

Changed 4 years ago by msiedlarek

Patch

comment:1 Changed 4 years ago by msiedlarek

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

comment:2 Changed 4 years ago by aaugustin

  • Needs documentation set
  • Needs tests set
  • Triage Stage changed from Unreviewed to Design 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 4 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 4 years ago by aaugustin

#15985 was a duplicate.

comment:5 Changed 3 years ago by aalbrecht

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

comment:6 Changed 3 years ago by aaugustin

  • Easy pickings set
  • Triage Stage changed from Design decision needed to Accepted

comment:7 Changed 3 years ago by aaugustin

#9549 is related.

comment:8 Changed 3 years ago by jpaugh64

  • 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 3 years ago by jpaugh64

Reincarnation of patch supporting the flush command as well

Changed 3 years ago by jpaugh64

Documentation for the (with-flush) patch

comment:9 Changed 3 years ago by jpaugh64

  • Cc jpaugh64 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 3 years ago by jpaugh64

  • Version changed from 1.3 to SVN

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

comment:11 Changed 3 years ago by aaugustin

  • 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 3 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 3 years ago by vlinhart

Changed 3 years ago by vlinhart

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

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

In [fedac99c859c626544d38fc0ea07207ef3fd101a]:

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

Thanks msiedlarek, jpaugh64 and vlinhart!

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

In [f0664dc8ae541b21e3cf421725e7933a9b3a799e]:

Made TestNoInitialDataLoading pass with MySQL (Refs #15926)

comment:15 Changed 3 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