我正在Heroku上運行Django 5.1 Web應用程序,並保留用戶數據。Django 1.5:如何使用South向現有表添加新模型字段而不必刪除表?
在本地,我只是給現有模型添加了一個新的char
字段,並且當我推送到Heroku時不想破壞任何內容。我知道Django 6引入了一個migrate
命令,但是Django 5沒有這樣的東西。我只有South
遷移工具。
我試圖在本地(在我的sqlite3數據庫上)關注South basic tutorial,以確保在Heroku上運行'真正'時不會破壞任何內容。一切都打破了......
(venv)$ python manage.py migrate forecasts
Running migrations for forecasts:
- Migrating forwards to 0002_auto__add_field_day_weather.
> forecasts:0001_initial
FATAL ERROR - The following SQL query failed: CREATE TABLE "forecasts_region" ("id" integer NOT NULL PRIMARY KEY, "url" varchar(200) NOT NULL UNIQUE, "name" varchar(200) NOT NULL, "nickname" varchar(10) NOT NULL)
The error was: table "forecasts_region" already exists
! Error found during real run of migration! Aborting.
! Since you have a database that does not support running
! schema-altering statements in transactions, we have had
! to leave it in an interim state between migrations.
! You *might* be able to recover with: = DROP TABLE "forecasts_region"; []
= DROP TABLE "forecasts_day"; []
= DROP TABLE "forecasts_tide"; []
! The South developers regret this has happened, and would
! like to gently persuade you to consider a slightly
! easier-to-deal-with DBMS (one that supports DDL transactions)
! NOTE: The error which caused the migration to fail is further up.
Error in migration: forecasts:0001_initial
DatabaseError: table "forecasts_region" already exists
我被迫DROP
這三個表,然後重新運行python manage.py syncdb
,然後python manage.py migrate forecasts
。這增加了新的字段,但我在這三個表中丟失了所有的數據。
我是害怕在現場版本上弄亂了事情,所以請問,我該怎麼做,按什麼順序?如果您可以包含最佳做法,爲了防止出現問題而保留數據,我們將不勝感激。另外,請握住我的手,因爲我從未使用過South
。謝謝!
是的,我忽略了運行'./manage.py convert_to_south myapp'。考慮到提供的錯誤信息,您認爲這是問題嗎?這似乎與我使用sqlite3數據庫的事實有關。此外,有關如何備份我的數據,以防萬一出現問題的任何提示? – sgarza62