0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【メモ】djangoのmigrationファイルで任意のsqlを実行する。

Posted at

任意のsqlをdjangoのマイグレーションファイルで追加する。


# Generated by Django 2.0.3 on 2019-06-16 08:38

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('residential', '0005_auto_20190616_1738'),
    ]

    operations = [
        migrations.RunSQL(
            "alter table mst_city add column geom geometry(Point, 4326)",
            "update mst_city set geom=st_SetSrid(st_MakePoint(lat, lng), 4326)"
        )
    ]

一番最後のmigrationファイルをdependencyに追加して、operationの配列に記載するだけ。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?