Set AUTOINCREMENT value in django table

后端 未结 1 1532
礼貌的吻别
礼貌的吻别 2021-01-15 01:04

I have the following table in mysql:

CREATE TABLE `portal_asset` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `asset_id` int(11) NOT NULL
) ENGINE=In         


        
相关标签:
1条回答
  • 2021-01-15 02:09

    You can use a RunSQL operation in your migrations to execute the necessary SQL:

    migrations.RunSQL("ALTER TABLE portal_asset AUTO_INCREMENT=1000000;")
    

    If you haven't run any migrations, you can add this to your first migration to ensure no rows are inserted before the new value is set. Otherwise you'll have to add this operation in a new migration. You can create a new, empty migration using python manage.py makemigrations --empty <yourappname>.

    0 讨论(0)
提交回复
热议问题