2017-08-08 18 views
0

私のデータベースの新しい列は、の端末とRoRから移行することはできません。 私は最初の一歩を取得:端末経由での移行なし

**$ rails g migration add_online_to_posts online:boolean** 

Running via Spring preloader in process 13406 
     invoke active_record 
     create db/migrate/20170808141302_add_online_to_posts.rb 

その後何も動作:

**$ rails db:migrate** 
rails aborted! 
ActiveRecord::DuplicateMigrationVersionError: 

Multiple migrations have the version number 20170725122210. 

/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:1257:in `validate' 
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:1123:in `initialize' 
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:1007:in `new' 
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:1007:in `up' 
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/migration.rb:985:in `migrate' 
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/tasks/database_tasks.rb:171:in `migrate' 
/home/projets/RoR_formation/vendor/bundle/gems/activerecord-5.1.2/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>' 
/home/projets/RoR_formation/vendor/bundle/gems/railties-5.1.2/lib/rails/commands/rake/rake_command.rb:21:in `block in perform' 
/home/projets/RoR_formation/vendor/bundle/gems/railties-5.1.2/lib/rails/commands/rake/rake_command.rb:18:in `perform' 
/home/projets/RoR_formation/vendor/bundle/gems/railties-5.1.2/lib/rails/command.rb:46:in `invoke' 
/home/projets/RoR_formation/vendor/bundle/gems/railties-5.1.2/lib/rails/commands.rb:16:in `<top (required)>' 
/home/projets/RoR_formation/bin/rails:9:in `require' 
/home/projets/RoR_formation/bin/rails:9:in `<top (required)>' 
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load' 
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call' 
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call' 
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/client.rb:30:in `run' 
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/bin/spring:49:in `<top (required)>' 
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load' 
/home/projets/RoR_formation/vendor/bundle/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>' 
/home/projets/RoR_formation/bin/spring:15:in `<top (required)>' 
bin/rails:3:in `load' 
bin/rails:3:in `<main>' 
Tasks: TOP => db:migrate 

私はIDEを経由して列を扱うことができます。 enter image description here

しかし、私はやるとき:

**$ Status Migration ID Migration Name** 
    up  20170725122210 Create posts table 
    up  20170726082500 Rename post title to intitule 
    up  20170728143925 Create categories 
    up  20170807110617 ********** NO FILE ********** 
down 20170808113533 Add slug to posts 
+0

どのようにして移行ファイルを作成しましたか?ジェネレータを使用したか、または移行ファイルをコピーして編集しましたか?移行ファイルは一意にバージョン管理する必要があります。 – MarsAtomic

+0

実際に私は端末を介して発電機を使用しました。しかし、チュートリアルの手順では、私は手動でファイルを削除しました – Kriss

答えて

0

あなたはすでにpreを使って移行を実行しています20170725122210を修正してください(削除した可能性もあります)。迅速な修正を行うには、最新の移行を20170725122211(またはスキーマ移行テーブルに含まれていないその他の番号)に変更します。また、rails db:schema:dumpを実行して、移行に存在しないテーブルについてはdb/schema.rbの出力を調べることもできます。

+0

実際に私は端末を介して発電機を使用しました。しかし、チュートリアルの手順では、ファイルを手動で削除しました。 ** rails db:schema:dump **を実行すると、何もしません。 。したがって、db/schema.rbの出力を調べることはできませんでした。私は私の最新の移行をリファクタリングしました。20170725122211 RubymineがIDEからのdb migrateの実行と作成を可能にすることも通知しました。このオプションを使うことができますか? – Kriss

関連する問題