我一直在准备我的应用程序进行生产,我正在努力耙我的数据库。它给了我这个错误:
PG::UndefinedTable: ERROR: relation "events" does not exist
: ALTER TABLE "events" ADD "code" character varying
这是我的database.yml文件:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
production:
<<: *default
database: db/production.postgresql
这是我的事件迁移文件:
class CreateEvents < ActiveRecord::Migration[5.0]
def change
create_table :events do |t|
t.string :name
t.string :partycode
t.references :user, foreign_key: true
t.timestamps
end
end
end
修改
当我运行rake db:migrate:status
时,我得到以下结果:
最后,这是我的gemfile:
source 'http://rubygems.org'
gem 'bootstrap-sass', '3.2.0.2'
gem 'bcrypt', '3.1.11'
gem 'will_paginate'
gem 'responders'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem "heroku"
gem 'coffee-script-source', '1.8.0'
gem 'jquery-rails'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'sqlite3'
gem 'byebug', platform: :mri
end
group :production do
gem 'web-console'
gem 'pg'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
ruby "2.2.4"
Lemme知道你还有什么需要解决我遇到的这个问题。谢谢:D
答案 0 :(得分:1)
看到您的rake db:migrate:status
有一个问题是迁移Add code to events
,应该在Create events
迁移之后,因为您正在event
进行更改,但表格正在进行中之后创建。所以你应该解决这个问题,暂时解决你可以做的事情:
rake db:migrate:up VERSION=20161219214142
20161219214142
是您Create Events
迁移的版本,因此这将为您运行特定的迁移并创建events
表,然后运行rake db:migrate
然后它会很好。