Skip to content

Instantly share code, notes, and snippets.

@Lapicher
Forked from sirodoht/migrate-django.md
Created July 17, 2018 22:19
Show Gist options
  • Select an option

  • Save Lapicher/ab280b3dfd12d2e70779795918914b29 to your computer and use it in GitHub Desktop.

Select an option

Save Lapicher/ab280b3dfd12d2e70779795918914b29 to your computer and use it in GitHub Desktop.

Revisions

  1. @sirodoht sirodoht revised this gist Aug 23, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion migrate-django.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,8 @@ Dump existing data:
    python3 manage.py dumpdata > datadump.json
    ```

    Change settings.py to your mysql.
    Change settings.py to Postgres backend.

    Make sure you can connect on PostgreSQL. Then:
    ```
    python3 manage.py migrate --run-syncdb
  2. @sirodoht sirodoht revised this gist Jul 10, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion migrate-django.md
    Original file line number Diff line number Diff line change
    @@ -26,4 +26,4 @@ Finally:
    python3 manage.py loaddata datadump.json
    ```
    > Source https://stackoverflow.com/questions/3034910/whats-the-best-way-to-migrate-a-django-db-from-sqlite-to-mysql
    > Source: https://stackoverflow.com/questions/3034910/whats-the-best-way-to-migrate-a-django-db-from-sqlite-to-mysql
  3. @sirodoht sirodoht revised this gist Jul 10, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions migrate-django.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # How to migrate Django from SQLite to PostgreSQL

    Dump existing data:
    ```
    python3 manage.py dumpdata > datadump.json
  4. @sirodoht sirodoht created this gist Jul 10, 2017.
    27 changes: 27 additions & 0 deletions migrate-django.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    Dump existing data:
    ```
    python3 manage.py dumpdata > datadump.json
    ```

    Change settings.py to your mysql.
    Make sure you can connect on PostgreSQL. Then:
    ```
    python3 manage.py migrate --run-syncdb
    ```

    Run this on Django shell to exclude contentype data
    ```
    python3 manage.py shell
    ```
    ```
    >>> from django.contrib.contenttypes.models import ContentType
    >>> ContentType.objects.all().delete()
    >>> quit()
    ````
    Finally:
    ```
    python3 manage.py loaddata datadump.json
    ```
    > Source https://stackoverflow.com/questions/3034910/whats-the-best-way-to-migrate-a-django-db-from-sqlite-to-mysql