【报错记录】rake aborted!运行错误

Published on:

错误信息:

apple@appledeMacBook-Pro ⮀ ~/job-listing/003 ⮀ ⭠ step2± ⮀ rake db:migrate
== 20170416113719 AddIsAdminToUser: migrating =================================
-- add_column(:user, :is_admin, :boolean, {:default=>false})
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: user: ALTER TABLE "user" ADD "is_admin" boolean DEFAULT 'f'
/Users/apple/.rvm/gems/ruby-2.3.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:91:in `initialize'

位置+问题描述:

招聘网站6-2章,rake db:migrate
增加is_admin的migration栏位信息,运行rake报错

错误排除方法:

看到splite3,立马想到Gemfile里的spring还没有注解掉——注解后不行;
猜测是数据库问题,用三兄弟——仍报错;
按照网页报错,运行bin/rails db:migrate RAILS_ENV=development无效;
马俊楠同学的logdown,发现model/user.rb打错字——仍报错;


1、用马同学的方法,删除migration文件再重新新建——成功
rake d migration add_is_admin_to_user
rake g migration add_is_admin_to_user
rake db:migrate

2、最佳解法:在slack上请教助教,发现问题出在user的s上,因为命令用add_is_admin_to_user,所以栏位填写的时候把users错写成user。

3、刚刚跑完 migrate 发现打错字

rake db:rollback (回退一次)
修改完
再跑rake db:migrate 

Comments

comments powered by Disqus