Postgresql Triggers and Django

38 views
Skip to first unread message

Philip Haynes

unread,
Dec 4, 2014, 4:28:53 PM12/4/14
to django...@googlegroups.com
Hi,
I have tracked back through the messages in this group and examined the documentation for version 1.7 of Django and I have a question.

The 1.7 documentation (https://docs.djangoproject.com/en/1.7/howto/initial-data/) describes the "Providing initial SQL data" functionality as deprecated. Is that referring to using this hook for any SQL processing or just for the loading of initial data? From the phrasing in the documentation it is not clear to me if the entire hook for loading SQL code after the CREATE TABLE statement is deprecated or whether it is just deprecated for initial data. The deprecation comment refers to using Migrations to achieve the purpose, I can do that, its just a bit more inconvenient than loading my sql directly.

FWIW, my goal is to insert triggers into a few places in the database. I would prefer triggers because I have non-Django processes that can interact with the database and it is most robust for me to have the RDBMS itself perform the work.

Anybody have a definitive understanding of the deprecation of the hook for loading app/<model_name>.sql ?

Thanks
Philip

Andreas Kuhne

unread,
Dec 4, 2014, 4:52:42 PM12/4/14
to django...@googlegroups.com
Hi Philip, 

I ran into this problem earlier today actually. The problem is that you can't provide initial data for populating the models (or tables). That's what this refers to. To provide initial data, you have to run a migration.

The initial-data information is only for loading the database with information (default users and so on), not for running arbitrary sql code. I think if you want to do that you will have to have a data migration, which you can run when the initial migration is run.

Regards,

Andréas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/02579470-4f77-43ce-b765-30ad2c53a03f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Carl Meyer

unread,
Dec 4, 2014, 4:56:56 PM12/4/14
to django...@googlegroups.com
Hi Philip,
The entire mechanism is deprecated in favor of using a migration with a
RunSQL operation. Already in 1.7, for any app using migrations, initial
SQL files will be ignored.

In a world in which database tables are constructed entirely via
migrations (which is already the case for any app with migrations, and
will be the case for all apps in Django 1.9), the initial-SQL feature
just doesn't make sense: it duplicates the RunSQL operation, and it is
unclear when in the chain of migrations it would be expected to run.

Carl

signature.asc
Reply all
Reply to author
Forward
0 new messages