Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

timgraham
Copy link
Member

@timgraham timgraham force-pushed the 14204 branch 2 times, most recently from 2144c6c to 2013763 Compare June 26, 2017 23:50
@timgraham
Copy link
Member Author

There are still some test failures with ./tests/runtests.py contenttypes_tests --parallel=1 or when running all tests without --parallel=1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how this will play with existing SQLite tables that don't have DEFERRABLE INITIALLY DEFERRED constraints. At this point I think the best course of action would be to mention it in the release notes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure exactly what the ramifications might be. Anything specific to mention besides what I wrote so far?

Copy link
Member

@charettes charettes Jun 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the text you added is appropriate. Makes me wonder if we would like to document how to migrate existing foreign keys to DEFERRABLE INITIALLY DEFERRED (which will be a bit complicated as it will require a table rebuild since SQLite doesn't support ALTER TABLE) or suggest PRAGMA defer_foreign_keys = ON should be issued on connection creation when entering a transaction for SQLite databases created with Django < 2.0.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to what charettes asked, but asked in a slightly different way:

Assumption: basic migrations will handle the table rebuild, like existing sqlite schema changes.

Question: if PRAGMA foreign_keys is going to be default on in django 2, how will the user "opt in" their old tables to a migration, without there being a difference in their model params?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably feasible to create a script or management command or similar to rebuild tables. I wasn't sure if it's needed; i.e. what circumstances will create a problem with non-upgraded tables? The problems in the test suite related to that seemed to be with flush which doesn't like a huge concern (if someone wants to do that, just delete the tables instead).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something along these lines would break on tables that haven't been rebuilt and still have IMMEDIATE foreign key constraints:

with transaction.atomic():
    # The following line will immediately fail now that foreign key
    # constraints are enforced and were created as IMMEDIATE
    # instead of INITIALLY DEFERRED.
    Book.objects.create(author_id=1)
    Author.objects.create(id=1)

We might want to mention that constraints used to be built as DEFERRABLE IMMEDIATE in the Foreign keys are now created with DEFERRABLE INITIALLY DEFERRED section and might require a rebuild to allow the above pattern to be used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I incorporate this into the release notes.

@timgraham timgraham force-pushed the 14204 branch 2 times, most recently from 4c7fd23 to bda157d Compare July 3, 2017 21:43
@timgraham timgraham changed the title [WIP] Fixed #14204 -- Added support for SQLite foreign key constraints. Fixed #14204 -- Added support for SQLite foreign key constraints. Jul 3, 2017
@timgraham timgraham force-pushed the 14204 branch 2 times, most recently from 3ff9e52 to 8524825 Compare July 10, 2017 17:12
Thanks Tim Graham for contributing to the patch and
Simon Charette for advice and review.
@timgraham timgraham merged commit 169c3b3 into django:master Jul 11, 2017
@timgraham timgraham deleted the 14204 branch July 11, 2017 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants