gpt4 book ai didi

MySQL 数据库迁移在 Rails 上失败

转载 作者:行者123 更新时间:2023-11-29 18:15:28 25 4
gpt4 key购买 nike

我有这个迁移文件:

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

我每次都必须这样做吗?

最佳答案

好的,这就是您需要做的:

首先回滚上次迁移,以便从头开始:

rake db:rollback

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

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

然后重新运行迁移:

rake db:migrate

关于MySQL 数据库迁移在 Rails 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47064934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com