Django Database Prefix

前端 未结 2 1193
生来不讨喜
生来不讨喜 2021-01-27 16:36

I need to merge two databases for two different apps. How can add prefix to all Django tables to avoid any conflict?

For example, option should look like:



        
2条回答
  •  庸人自扰
    2021-01-27 17:24

    You can use meta options for model,

    class ModelHere():
          class Meta:
              db_table = "tablenamehere"
    

    Edit

    If you want to add prefix to all of your tables including auth_user, auth_group, etc. Then you are looking for something like django-table-prefix. Just install and add some settings to settings file and you are done.

    1. Add 'table_prefix', to installed apps,
    2. Set the table prefix as DB_PREFIX = 'nifty_prefix'

    Then run syncdb and the output will be,

    Creating tables ...
    Creating table nifty_prefix_auth_permission
    Creating table nifty_prefix_auth_group_permissions
    Creating table nifty_prefix_auth_group
    Creating table nifty_prefix_auth_user_groups
    Creating table nifty_prefix_auth_user_user_permissions
    Creating table nifty_prefix_auth_user
    Creating table nifty_prefix_django_content_type
    Creating table nifty_prefix_django_session
    Creating table nifty_prefix_django_site
    

提交回复
热议问题