dimanche 28 avril 2019

No Such Table when Running Django (2.0.13) Tests with SQLite3 Database

When attempting to run Django (version 2.0.13) automated testing a test isn throwing an operational error, "no such table". The table exists in my production database, and there exists migration code to create the table in the migration modules, however when attempting to create an instance of a model based on the table I get django.db.utils.OperationalError: no such table: test_table

The testSettings.py looks as such:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'default',
        'TEST_NAME': 'default',
        'USER': 'u',
        'PASSWORD': 'p',
        'HOST': 'localhost',
        'PORT': '',
        'TIME_ZONE': 'Australia/Sydney'
    },
}

MIGRATION_MODULES = {
    ...
    'app': 'app.test.test_migration_app_0001_initial',
}

And it exists in the migration file for testing:

migrations.CreateModel(
  name='Test_Table',
  fields=[
    ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
    ('name', models.CharField(max_length=30, unique=True)),
  ],
),
...
migrations.AddField(
  model_name='test_subtable',
  name='test_table',
  field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='test', to='app.test_table'),
),

Of possible note, the database table is using the INNODB engine.

Aucun commentaire:

Enregistrer un commentaire