Postgres (sqlmigrate) FK to M2M without RunPython

49 views
Skip to first unread message

Maksym Mospanenko

unread,
Mar 6, 2017, 8:23:21 PM3/6/17
to Django users
Hello! I want to migrate data with schema migrations but I can't run any python code on database server - only raw sql (postgres).
How can I move fk column data to m2m table's fk column?

Melvyn Sopacua

unread,
Mar 7, 2017, 4:18:01 AM3/7/17
to django...@googlegroups.com

On the server you can run python code:

python manage.py sqlmigrate app_label migration_name |psql dbname

 

Or save the output, put it on db server and load it there.

I don't see why though. Just run migrate on the server that runs django.

--

Melvyn Sopacua

Daniel Roseman

unread,
Mar 7, 2017, 6:14:31 AM3/7/17
to Django users
Schema migrations don't run on the database server, they run on the app server with the rest of your Django code and communicate with the database in exactly the same way. If you can run Django, you can run migrations.
--
DR.

Maksym Mospanenko

unread,
Mar 8, 2017, 6:42:32 AM3/8/17
to Django users
Yes but I have to run on db server directly (via export sqlmigrate). Djando's manage.py can generate sql only for schema migrations - not for RunPython data migrations. 

вівторок, 7 березня 2017 р. 13:14:31 UTC+2 користувач Daniel Roseman написав:

Maksym Mospanenko

unread,
Mar 8, 2017, 6:47:17 AM3/8/17
to Django users
We don't have access to db server (only via custom django backend driver) in our configuration (security reasons). So we have to export raw sql for schema migrations manually and we can't generate sql for data migrations (because it is python's logic). 

вівторок, 7 березня 2017 р. 11:18:01 UTC+2 користувач Melvyn Sopacua написав:

Melvyn Sopacua

unread,
Mar 8, 2017, 6:58:10 AM3/8/17
to django...@googlegroups.com

On Wednesday 08 March 2017 03:42:31 Maksym Mospanenko wrote:

> Yes but I have to run on db server directly (via export sqlmigrate).

 

No, you don't.

 

> Djando's manage.py can generate sql only for schema migrations - not

> for RunPython data migrations.

 

But you're not creating migrations, you're applying migrations. Please review the difference between "makemigrations" and "migrate" command.

 

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages