![](/img/trans.png)
[英]heroku rake db:migrate rake aborted! unable to open database
[英]rake aborted database will not migrate
我分別為“啟動”創建了模型,視圖和控制器(沒有腳手架)。 我有一個文件db> migrate>'201 ..._ create_startups.rb',代碼如下:
class CreateStartups < ActiveRecord::Migration
def change
create_table :startups do |t|
t.string :name
t.string :location
t.string :description
t.timestamps null: false
end
end
end
我運行了“ bundle exec rake db:migrate”,並且得到了以下響應:
== 20141126011749 CreateStartups: migrating ===================================
-- create_table(:startups)
-> 0.0155s
== 20141126011749 CreateStartups: migrated (0.0159s) ==========================
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (1 for 0)/Users/kevinmircovich/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `initialize'
一旦運行本地服務器並轉到瀏覽器以查看我的應用程序,我將收到以下消息:
Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development
Extracted source (around line #393):
392 def check_pending!(connection = Base.connection)
393 raise ActiveRecord::PendingMigrationError if ActiveRecord::Migrator.needs_migration?>.>(connection)
394 end
395
396 def load_schema_if_pending!
我運行了“ bin / rake db:migrate RAILS_ENV = development”,並且遇到了與運行“ bundle exec rake db:migrate”時發生的錯誤相同的錯誤:
參數數目錯誤(1代表0)
無需在時間戳上“ null:false”:不是用戶輸入:這些是由活動模型本身設置的,因此您可以刪除參數。
在Rails遷移中,t.timestamp宏添加了兩列,created_at和updated_at。 這些特殊列(如果存在)由Active Record自動管理。
創建和更新新的記錄后,它將自動更新。
請從t.timestamp中刪除null:false參數。
class CreateStartups < ActiveRecord::Migration
def change
create_table :startups do |t|
t.string :name
t.string :location
t.string :description
t.timestamps
end
end
end
運行rake:db migration時收到類似的錯誤。 為了解決我的問題,我運行rake:db drop來刪除數據庫,因為我處於開發模式而沒有生產數據庫。 然后,我使用rake db:create重新創建數據庫,然后成功運行rake db:migrate。
運行rake db:db時發生錯誤:ActiveActive :: PendingMigrationError正在遷移中; 運行“ bin / rake db:migrate RAILS_ENV = development”來解決此問題。
解決方法:
rake db:drop-這將清除數據庫中的數據rake db:create rake db:migrate
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.