迁移数据库时出现RubyOnRails错误

时间:2019-06-21 20:27:35

标签: ruby-on-rails database-migration

此处错误输出,https://github.com/Marium36/blog/blob/master/errors

GitHub代码https://github.com/Marium36/blog/

我正在关注Ruby On Rails在线课程。

到目前为止,我已经能够按照说明创建User的Scaffold,并将两个字段添加到预先存在的表Post和Comments

rails g scaffold User first_name:string last_name:string
rails g migration AddUseridToPosts user:references
rails g migration AddUseridToComments user:references

当我尝试运行rake db:migrate时,我发现了很多错误,充满了多页内容。

可能出什么问题了???

这是error

的开头
ruby@ruby-VirtualBox:~/blog$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:migrate
== 20190621201248 AddUseridToPosts: migrating =================================
-- add_reference(:posts, :user, {:null=>false, :foreign_key=>true})
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: Cannot add a NOT NULL column with default value NULL
/home/ruby/.rvm/gems/ruby-2.6.3/gems/sqlite3-1.4.1/lib/sqlite3/database.rb:147:in `initialize'
/home/ruby/.rvm/gems/ruby-2.6.3/gems/sqlite3-1.4.1/lib/sqlite3/database.rb:147:in `new'
/home/ruby/.rvm/gems/ruby-2.6.3/gems/sqlite3-1.4.1/lib/sqlite3/database.rb:147:in `prepare'
/home/ruby/.rvm/gems/ruby-2.6.3/gems/sqlite3-1.4.1/lib/sqlite3/database.rb:193:in `execute'

0 个答案:

没有答案