Mlier
Mlier

Reputation: 121

Upgrade django-synchro for django 2.2 : OperationalError - no such table: django_content_type"

I am trying to upgrade django-synchro to django 2.2. I have already upgraded the project to django 2.1 but I have now a problem with ContentType object

The upgraded version to django 2.1 can be found here

(python runtests.py works, all tests pass)

With django 2.2.3 I have the error

django.db.utils.OperationalError: no such table: django_content_type

It seems that at initialisation, migrations are done on default database and the rest it is done on test database (in memory). So ContentType are not seen in the rest of the code. An error occur when models.py is read (content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE))

Any ideas would be very appreciated...

I have looked in Django 2.2 release notes

There are two backwards incompatible changes in 2.2 that can maybe do the error :

TransactionTestCase serialized data loading : Initial data migrations are now loaded in TransactionTestCase at the end of the test, after the database flush. In older versions, this data was loaded at the beginning of the test, but this prevents the test --keepdb option from working properly (the database was empty at the end of the whole test suite). This change shouldn’t have an impact on your tests unless you’ve customized TransactionTestCase’s internals.

Test : Deferrable database constraints are now checked at the end of each TestCase test on SQLite 3.20+, just like on other backends that support deferrable constraints. These checks aren’t implemented for older versions of SQLite because they would require expensive table introspection there.

Upvotes: 3

Views: 441

Answers (1)

Steve Bradshaw
Steve Bradshaw

Reputation: 817

For me, it was this note from the Django 2.2 release notes

Tests will fail on SQLite if apps without migrations have relations to apps with migrations. This has been a documented restriction since migrations were added in Django 1.7, but it fails more reliably now. You’ll see tests failing with errors like no such table: _. This was observed with several third-party apps that had models in tests without migrations. You must add migrations for such models.

I'm not sure if the error message is particularly helpful. But a round of upgrades and checking that I had no really old django modules lying around seemed to fix it.

Upvotes: 1

Related Questions