As the Ticket https://code.djangoproject.com/ticket/16550 is closed, I will
continue the discussion here on the mailing list.
The reason for the ticket is that the Django test runner does not provide a
way to run custom SQL. This makes sense when users want to load custom SQL
*data*, but not when modifying the way the database works.
Here's my comment from the issue comment thread:
I agree very much with the comment above, in that there should be a way to
execute custom SQL before and after running syncdb. This should not be used
to load custom data, which is truncated anyways, but to alter the schema,
create new types or load extensions.
In my case, I have to load the Postgres citext extension:
CREATE EXTENSION IF NOT EXISTS citext;
Because I have to create a database manually before running syncdb, I can
run my custom SQL in my database and then use it normally with Django. But
because the extensions are database specific, when running the tests (which
create their own database) they fail because the extension is not present.
This means that contrary to the comment by russellm, the *test database*
introduces an inconsistency between the way tables work during a test case
and the way they work in production.
Another widely used extension is the hstore extension.
As a workaround, I loaded the extension in the default postgres template.
psql -d template1 -c 'CREATE EXTENSION citext;'
But that means that any new database I create will contain the citext
extension, which might not be what I want.
Therefore I suggest that you add some pre syncdb and post syncdb hooks to
run custom SQL, and to mention in the docs that this should *not* be used
to load custom data, but to create new types and alter the schema, so that
it *matches the production database*. The data is truncated anyways.
I vote for reopen.
What do you think about this issue? Does anyone else agree that there
should be a way to run custom SQL in order not to create inconsistencies
between the test and production database?
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-developers/-/KsrsEf7XOA8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.