My Django app depends on a database with some triggers setup. I use this part of the documentation to set up the triggers in the test database for the pytest runner.
@pytest.fixture(scope='session')
def django_db_setup(django_db_setup, django_db_blocker):
with django_db_blocker.unblock():
cur = connection.cursor()
cur.execute([...]) # Set it up
I run my tests with --nomigrations
and it works as expected. Without --nomigrations
(test runs migrations first), the triggers are not working.
So trying to debug this, I've confirmed
psql test_<mydb>
and looking in the pg_trigger
table) Let me just stress once more that the tests pass when run without migrations and testing the functionality when running the dev server against my dev db I can also confirm that it works
So, my question is: Is there any reason that running with migrations should do things differently? Or is it likely that my migrations do something obscure which makes things fail, ie it is my own fault?
Placing trigger in django_db_setup
worked for me
@pytest.fixture(scope='session')
def django_db_setup(django_db_setup, django_db_blocker):
with django_db_blocker.unblock():
cur = connection.cursor()
cur.execute('''CREATE TRIGGER search_vector_update BEFORE INSERT OR UPDATE
ON xml_templates_template FOR EACH ROW EXECUTE PROCEDURE
tsvector_update_trigger(search_vector, 'pg_catalog.english', name, description, info);
''')
pytest (4.4.1) is run with --nomigrations
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.