简体   繁体   中英

Dynamic table and model generate in django

I want to create some database tables and models.Model on api call in django. I created on demand Model model = type(str(project_slug + "_tbl_name"), (models.Model,), attrs) and I want to create table like this db.create_table(table_name, fields) create_table was from south but south is not available in Django 1.11 what I am using

How can I generate Model and database tables programmatically?

https://docs.djangoproject.com/en/1.11/ref/schema-editor/#create-model

example:

with connection.schema_editor() as schema_editor:
   schema_editor.create_model(my_model)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM