I'm trying to add pytest-django to my current pytest3/Django1.7 environment.
Currently we have not been using the plugin and have been suffering from shared state between certain tests
Everything seems to visually look good and the tests seem to pass until the end when I get the following error messages:
request = <SubRequest '_django_db_marker' for <Function 'test_filter_recurring_outside_sync_window'>>
@pytest.fixture(autouse=True)
def _django_db_marker(request):
"""Implement the django_db marker, internal to pytest-django.
This will dynamically request the ``db`` or ``transactional_db``
fixtures as required by the django_db marker.
"""
marker = request.keywords.get('django_db', None)
if marker:
validate_django_db(marker)
if marker.transaction:
getfixturevalue(request, 'transactional_db')
else:
getfixturevalue(request, 'db')
ve/lib/python2.7/site-packages/pytest_django/plugin.py:376:
self = <django.db.backends.sqlite3.base.SQLiteCursorWrapper object at 0x11976a478>
query = 'SELECT "django_migrations"."app", "django_migrations"."name" FROM "django_migrations"', params = ()
def execute(self, query, params=None):
if params is None:
return Database.Cursor.execute(self, query)
query = self.convert_query(query)
> return Database.Cursor.execute(self, query, params)
E OperationalError: no such table: django_migrations
ve/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:485: OperationalError
I tried creating the table with ensure_schema
in the conftest.py
.
I've tried every option of --nomigrations
and --create-db
to pytest
.
I'm guessing it's a weird configuration problem I have with a legacy system, but I'm not sure where to start looking. Anyone have suggestions?
It looks like may be an issue with migration.
Running ./manage.py schemamigration research --auto
shows that most of the fields don't have any defaults specified.
Next, you then run ./manage.py schemamigration research --init
followed by ./manage.py migrate research
This worked for me after I created the table:
python manage.py migrate --run-syncdb
NOTE: Don't forget to run python makemigrations first, i.e. python manage.py makemigrations {name of the app where patients model is}
Helpful tips: There is a table generated by
django
calleddjango_migrations
which keeps track of what migrations have been applied. If you delete yourmigrations
, re-generate them and try tomigrate
without deleting the records from the table, thendjango
will think it already applied them. You should never delete your migrations, as it will cause django to get confused.You can skip the migrations step if you are actively developing If you are actively developing and want to skip the entire
migrations
system you can, but once you start usingmigrations
, never delete them. Here is what I use while developing a new project:dropdb mydb && createdb mydb && python manage.py migrate --run-syncdb && python manage.py loaddata initial
First, it drops the database and all data. Then it creates an empty one. The
--run-syncdb
generates the schema and theloaddata
loads data from a fixtures file.So, if you are still developing and can delete all your data and move what you care about to a fixtures file, then you can delete all your migration folders. You then can run the command above each time you change your model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With