首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mysql数据库在Rails上迁移失败

Mysql数据库在Rails上迁移失败
EN

Stack Overflow用户
提问于 2017-11-02 06:55:45
回答 1查看 48关注 0票数 0

我有这个迁移文件:

代码语言:javascript
复制
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

它在最后一行失败:

代码语言:javascript
复制
-- 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文件指定创建的特定表:

代码语言:javascript
复制
#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时,也会发生这种情况:

代码语言:javascript
复制
 mysql
ERROR 1045 (28000): Access denied for user 'jwan'@'localhost' (using password: NO)

但这是可行的:

代码语言:javascript
复制
mysql -u root

我每次都要这么做吗?

EN

回答 1

Stack Overflow用户

发布于 2017-11-02 07:22:43

好的,下面是你需要做的:

首先回滚上一次迁移,这样您就可以从头开始:

代码语言:javascript
复制
rake db:rollback

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

未知密钥::null。有效键为::唯一,:顺序,:名称,:其中,:长度,:内部,:使用,:算法,

然后重新运行迁移:

代码语言:javascript
复制
rake db:migrate
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47064934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档