在Rails上Mysql数据库迁移失败

时间:2017-11-01 22:55:45

标签: mysql ruby-on-rails

我有这个迁移文件:

class InitialDigitizationWork < ActiveRecord::Migration
  def self.up
    create_table :digitizations do |t|
      t.string :submission_code, :null => false
      t.timestamps
    end

    add_index :digitizations, :submission_code, :unique => true

    create_table :digitized_pieces do |t|
      t.integer :digitization_id, :null => false
      t.integer :position, :null => false
      t.string :piece_type, :default => "Page"
      t.timestamps
    end

    add_index :digitized_pieces, :digitization_id

    create_table :digitized_views do |t|
      t.integer :digitized_piece_id, :null => false
      t.string :initial_file_name
      t.string :attachment_file_name
      t.string :attachment_content_type
      t.integer :attachment_file_size
      t.datetime :attachment_updated_at
      t.integer :position, :null => false
      t.boolean :is_primary, :default => false
      t.timestamps
    end

    add_index :digitized_views, :digitized_piece_id, :null => false
  end

并在最后一行失败:

-- add_index(:digitized_views, :digitized_piece_id, {:null=>false})
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

Unknown key: :null. Valid keys are: :unique, :order, :name, :where, :length, :internal, :using, :algorithm,

任何人都知道发生了什么事?

这里令人烦恼的是,由于最后一行失败,我无法再次重新运行迁移,因为顶部digitizations上的表存在。我知道如何使用Postgresql并访问由此yml文件指定的特定表:

#SQLite version 3.x
 #gem install sqlite3-ruby (not necessary on OS X Leopard)

development:
  adapter: mysql2
  database: arthouse_development
  username: root
  password:
  host: localhost
  port: 3306
  #socket: /tmp/mysql.sock

legacy_development:
  adapter: mysql2
  database: arthouse_legacy_development
  username: root
  password:
  host: localhost
  port: 3306

有人知道如何在这里安装数据库吗?

任何人都知道可能会发生什么?这是我第一次使用mysql并可以使用一些帮助。

当我输入mysql时,会发生这种情况:

 mysql
ERROR 1045 (28000): Access denied for user 'jwan'@'localhost' (using password: NO)

但这有效:

mysql -u root

我每次都必须这样做吗?

1 个答案:

答案 0 :(得分:0)

好的,这就是你需要做的事情:

首先回滚上一次迁移,以便从干净的平台开始:

rake db:rollback

然后删除索引上的default=> null约束。错误消息明确指出它不是已知的key

  

未知密钥:: null。有效密钥是:: unique,:order,:name,:where,   :length,:internal,:using,:algorithm,

然后重新运行迁移:

rake db:migrate