Django: How to migrate dynamic models made at runtime

前端 未结 2 1416
旧时难觅i
旧时难觅i 2021-02-20 04:58

In my Django app, a specific user input will result in the creation of a new model. Here is the code I am using to create the model and register it.

model = type         


        
2条回答
  •  离开以前
    2021-02-20 05:14

    Subprocess can migrate your model using migrate command. So try this it will work

    import subprocess
    command = 'python manage.py migrate'
    proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    stdout, stderr = proc.communicate(command)
    

    Read also this https://code.djangoproject.com/wiki/DynamicModels If it can help for create dynamic model

提交回复
热议问题