[英]Rails need to migrate everytime restart server
將我的應用程序部署到heroku
,我收到一些有關遷移的錯誤。
這樣我就合並了所有的遷移,只需要創建包含所有finally 屬性的表文件,刪除編輯表。
現在,每次重新啟動服務器(本地主機)時,我都必須再次db:migrate
才能正常工作。
當我只使用db:migrate
,錯誤說: table 'product' already existed'
所以我必須先db:drop
,然后db:migrate
才能使我的應用程序工作這花了我很多時間。 我該如何解決這個問題? 這是我的遷移狀態:
up 20190306060445 ********** NO FILE ********** down 20190306060545 Create product up 20190307035103 Create active storage tablesactive storage up 20190308045037 ********** NO FILE ********** up 20190308071304 ********** NO FILE ********** down 20190308072304 Devise create users up 20190308074025 Devise create admins down 20190308082018 Create categories up 20190308083018 ********** NO FILE ********** up 20190311041416 ********** NO FILE ********** up 20190313084429 Create payment up 20190314024236 Create cart up 20190314024911 Create cart product up 20190314035334 Create messages up 20190314145333 Create payment item up 20190314151340 ********** NO FILE ********** up 20190315020606 ********** NO FILE ********** up 20190318073652 Create voucher up 20190319035819 ********** NO FILE ********** up 20190319134032 Contacts up 20190320034249 ********** NO FILE ********** up 20190320062223 ********** NO FILE ********** up 20190325132236 ********** NO FILE ********** up 20190325155829 ********** NO FILE ********** up 20190329095529 ********** NO FILE ********** up 20190329110656 ********** NO FILE ********** up 20190330145000 ********** NO FILE ********** up 20190331162926 ********** NO FILE ********** up 20190408155326 ********** NO FILE ********** up 20190419055934 ********** NO FILE ********** up 20190419060341 ********** NO FILE ********** up 20190502105847 ********** NO FILE ********** up 20190502110019 Add stock up 20190506114910 ********** NO FILE ********** up 20190506115146 ********** NO FILE ********** up 20190506115302 ********** NO FILE ********** up 20190513042021 ********** NO FILE ********** up 20190513050115 ********** NO FILE ********** up 20190514025220 ********** NO FILE ********** up 20190514031046 ********** NO FILE ********** up 20190516010239 Create comment up 20190516020021 ********** NO FILE ********** up 20190517132706 Create notification up 20190524152143 Create brands up 20190527040142 ********** NO FILE ********** up 20190528113143 Add columns devise up 20190528113658 Add columns devise 1 up 20190531125307 Create news up 20190531144908 Create ckeditor assets up 20190601100118 Create news products up 20190602144319 Create type of news up 20190602155208 ********** NO FILE ********** up 20190603062824 ********** NO FILE ********** up 20190606172629 ********** NO FILE ********** up 20190607074100 ********** NO FILE ********** up 20190607122350 ********** NO FILE ********** up 20190607140214 ********** NO FILE ********** up 20190608082804 ********** NO FILE ********** up 20190609051100 Add omniauth to users up 20190611115405 ********** NO FILE ********** up 20190612071933 Create table carousels up 20190612100433 ********** NO FILE ********** up 20190613082404 ********** NO FILE ********** up 20190614131413 ********** NO FILE ********** up 20190615161828 ********** NO FILE ********** up 20190617154212 Create district up 20190617154602 Create province up 20190619140034 Create ward up 20190620134528 ********** NO FILE ********** down 20190620140214 Convert tables to utf8 v1 up 20190622123753 ********** NO FILE **********
在更改所有遷移時,您已經創建了“新”遷移。 rails db:migrate
正在嘗試將這些“新”遷移應用到已經存在的數據庫中。 (已應用的遷移列表保存在schema_migrations
表中)。 我們可以看到所有的down
遷移都是沒有被應用的。 包括down 20190306060545 Create product
。
由於這是一個正在運行的生產數據庫,大概product
表已經存在。 當 Rails 運行遷移20190306060545 Create product
可能嘗試create_table :product
,它將失敗,因為product
已經存在。
避免這種情況的一種方法是首先檢查該表是否存在於您的“創建表”遷移中。 如果是,什么都不做。
if table_exists?(:product)
return
end
為了在開發中重現這一點......
rails db:migrate:reset
rails db:migrate
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.