2016-08-03 76 views
1

我得到的錯誤:如何使用新表遷移heroku上的本地數據庫?

Exception Value:  
no such table: hello_surname 

當我試圖證明訪問姓模式

在我的models.py視圖

class Surname(models.Model): 
    created = models.DateTimeField('date created', auto_now_add=True) 
    name = models.CharField(max_length=35) 

我試圖運行遷移$ heroku run python manage.py migrate

輸出:

Running python manage.py migrate on ⬢ sleepy-fjord... up, run.7027 

Operations to perform: 
    Apply all migrations: sessions, auth, hello, contenttypes, admin 
Running migrations: 
    No migrations to apply. 
    Your models have changes that are not yet reflected in a migration, and so won't be applied. 
    Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them. 

然後我運行$ heroku run python manage.py makemigrations

輸出:

Running python manage.py makemigrations on ⬢ sleepy-fjord... up, run.8567 
Migrations for 'hello': 
    0002_surname.py: 
    - Create model Surname 

當我再次運行頂部遷移,它只是提供了輸出,當我跑了它的第一次相同。好像我在這裏錯過了一個步驟,但輸出我似乎無法自己弄清楚。任何人都知道解決方案

+0

./manage.py makemigrations myappname – e4c5

+0

所以你的意思是說當你在'$ heroku運行python manage.py makemigrations'後執行'$ heroku運行python manage.py migrate'時,你仍然會得到** No migrations to應用**以及**您的模型的變化尚未反映在遷移中,因此不會被應用。或者只是**沒有遷移申請** ?? –

回答

0

必須運行使遷移本地,提交結果,然後運行在Heroku上遷移。

+0

對不起,我對這個概念有點新意,你會如何在本地專門運行它? – hakonbogen

+1

如果我沒有錯,那麼@Daniel的意思是說,你只需要簡單地將'python manage.py makemigrations',然後'python manage.py migrate'放在你的本地而不是heroku上。然後你需要對heroku進行提交,即'git push heroku master',然後在heroku上運行遷移。我是丹尼爾還是我錯過了什麼? –

相關問題