Django: What are the best practices to migrate a project from sqlite to PostgreSQL

后端 未结 7 1209
礼貌的吻别
礼貌的吻别 2020-12-04 10:25

I need to migrate a complex project from sqlite to PostgreSQL. A lot of people seems to have problem with foreign keys, data truncature and so on...

  • Is there a
7条回答
  •  不知归路
    2020-12-04 10:49

    Another way of doing this may be to use multiple databases.

    http://docs.djangoproject.com/en/dev/topics/db/multi-db/

    It is important you read this section.

    http://docs.djangoproject.com/en/dev/topics/db/multi-db/#moving-an-object-from-one-database-to-another

    From what I understand that means that provided there is no data in your new DB, from fixtures for example you could do

    queryset = MyModel.objects.using("old-db").all()
    for obj in queryset:
        obj.save(using="new-db")
    

    Because that should preserve the primary keys I don't think there'd be any foreign key issues.

提交回复
热议问题