How to migrate Django models from mysql to sqlite (or between any two database systems)?

后端 未结 4 1741
后悔当初
后悔当初 2021-02-06 04:42

I have a Django deployment in production that uses MySQL.

I would like to do further development with SQLite, so I would like to import my existing data to an SQLite dat

4条回答
  •  野的像风
    2021-02-06 05:32

    If you have contenttypes in installed app

    INSTALLED_APPS = (
        'django.contrib.contenttypes',
    )
    

    Use script like what for copying you entry to new base:

    from django.contrib.contenttypes.models import ContentType
    
        def run():
    
            def do(Table):
                if Table is not None:
                    table_objects = Table.objects.all()
                    for i in table_objects:
                        i.save(using='slave')
    
            ContentType.objects.using('slave').all().delete()
    
            for i in ContentType.objects.all():
                do(i.model_class())
    

    See full manual here

提交回复
热议问题