migrate和syncdb的区别(转载)
先說結論:沒區別.
從官方文檔的意思來看,現在他已經成為migrate命令的同義詞了,和migrate命令有相同的作用。
Deprecated since version 1.7:?This command has been deprecated in favor of the?migrate?command, which performs both the old behavior as well as executing migrations. It is now just an alias to that command
migrate命令的作用:
migrate [<app_label> [<migrationname>]]
django-admin migrate
New in Django 1.7.
Synchronizes the database state with the current set of models and migrations. Migrations, their relationship with apps and more are covered in depth in?the migrations documentation.
The behavior of this command changes depending on the arguments provided:
- No arguments: All migrated apps have all of their migrations run, and all unmigrated apps are synchronized with the database,
- <app_label>: The specified app has its migrations run, up to the most recent migration. This may involve running other apps’ migrations too, due to dependencies.
- <app_label>?<migrationname>: Brings the database schema to a state where the named migration is applied, but no later migrations in the same app are applied. This may involve unapplying migrations if you have previously migrated past the named migration. Use the name?zero?to unapply all migrations for an app.
Unlike?syncdb, this command does not prompt you to create a superuser if one doesn’t exist (assuming you are using?django.contrib.auth). Use?createsuperuser?to do that if you wish.
The?--database?option can be used to specify the database to migrate.
--fake
The?--fake?option tells Django to mark the migrations as having been applied or unapplied, but without actually running the SQL to change your database schema.
This is intended for advanced users to manipulate the current migration state directly if they’re manually applying changes; be warned that using?--fake?runs the risk of putting the migration state table into a state where manual recovery will be needed to make migrations run correctly.
New in Django 1.8.
--fake-initial
The?--fake-initial?option can be used to allow Django to skip an app’s initial migration if all database tables with the names of all models created by all?CreateModel?operations in that migration already exist. This option is intended for use when first running migrations against a database that preexisted the use of migrations. This option does not, however, check for matching database schema beyond matching table names and so is only safe to use if you are confident that your existing schema matches what is recorded in your initial migration.
Deprecated since version 1.8:?The?--list?option has been moved to the?showmigrations?command.
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的migrate和syncdb的区别(转载)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: RuntimeError: Model
- 下一篇: Django的电子商务网站的调研