隨著Django 開發人員的進步,重建專案結構背景
Django 1.7 及更高版本的解決方案
<code class="python">python manage.py makemigrations old_app --empty</code>
<code class="python">class Migration(migrations.Migration): dependencies = [] database_operations = [ migrations.RenameModel('TheModel', 'newapp_themodel') ] state_operations = [ migrations.DeleteModel('TheModel') ] operations = [ migrations.SeparateDatabaseAndState( database_operations=database_operations, state_operations=state_operations) ]</code>
<code class="python">python manage.py makemigrations new_app</code>
<code class="python">class Migration(migrations.Migration): dependencies = [ ('old_app', 'above_migration') ] state_operations = [ migrations.CreateModel( name='TheModel', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ], options={ 'db_table': 'newapp_themodel', }, bases=(models.Model,), ) ] operations = [ migrations.SeparateDatabaseAndState(state_operations=state_operations) ]</code>
以上是如何在 Django 1.7 中的 Django 應用程式之間遷移模型?的詳細內容。更多資訊請關注PHP中文網其他相關文章!