環境:
ruby 2.6.3
Rails 6.0.0
Railsでタスクアプリを作成中dbを削除して作り直したのですが、下記の
エラー画面が出てしまいました。
調べてみて
bundle exec rake db:migrate
をしてみたのですが、ターミナルでこのようなメッセージが出ました。
== 20191020071103 AddUserIdToTasks: migrating ================================= -- execute("DELLETE FROM tasks;") rake aborted! StandardError: An error has occurred, this and all later migrations canceled: PG::SyntaxError: ERROR: syntax error at or near "DELLETE" LINE 1: DELLETE FROM tasks; ^ /Users/mymac/study/taskleaf/db/migrate/20191020071103_add_user_id_to_tasks.rb:3:in `up' /Users/mymac/.rbenv/versions/2.6.3/bin/bundle:23:in `load' /Users/mymac/.rbenv/versions/2.6.3/bin/bundle:23:in `<main>' Caused by: ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near "DELLETE" LINE 1: DELLETE FROM tasks; ^ /Users/mymac/study/taskleaf/db/migrate/20191020071103_add_user_id_to_tasks.rb:3:in `up' /Users/mymac/.rbenv/versions/2.6.3/bin/bundle:23:in `load' /Users/mymac/.rbenv/versions/2.6.3/bin/bundle:23:in `<main>' Caused by: PG::SyntaxError: ERROR: syntax error at or near "DELLETE" LINE 1: DELLETE FROM tasks; ^ /Users/mymac/study/taskleaf/db/migrate/20191020071103_add_user_id_to_tasks.rb:3:in `up' /Users/mymac/.rbenv/versions/2.6.3/bin/bundle:23:in `load' /Users/mymac/.rbenv/versions/2.6.3/bin/bundle:23:in `<main>' Tasks: TOP => db:migrate (See full trace by running task with --trace)
教えて頂けると助かります。よろしくお願いいたします。
■追記■
migrationファイルです(downの最初です)
class ChangeTaskNameLimit30 < ActiveRecord::Migration[6.0] def up change_column :tasks, :name, :string, limit:30 end def down change_column :tasks, :name, :string end end
migrationファイルです(念の為downの2つ目です)
class AddUserIdToTasks < ActiveRecord::Migration[6.0] def up execute 'DELLETE FROM tasks;' add_reference :tasks, :user, null: false, index: true end def down remove_reference :tasks, :user, index: true end end
$rails db:migrate:status の結果です
database: taskleaf_development Status Migration ID Migration Name -------------------------------------------------- up 20191017095612 Create tasks up 20191019012825 Rename descriprion column to tasks up 20191020005240 Change tasks name not null up 20191020005913 Change task name limit30 up 20191020023534 Create users up 20191020025503 Add admin to users down 20191020071103 Add user id to tasks
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/10/20 13:48
2019/10/20 14:08
2019/10/21 22:24
2019/10/21 22:46