gpt4 book ai didi

mysql - rake 中止! StandardError : An error has occurred, 所有后续迁移均已取消:

转载 作者:行者123 更新时间:2023-11-29 17:47:08 24 4
gpt4 key购买 nike

sania@sania-Swift-SF314-52:~/library$ rake db:migrate

== 20180407084831 书籍:迁移 =========================================== ===-- 创建表(:书籍) rake 中止!StandardError:发生错误,所有后续迁移均已取消:

Mysql2::Error: Table 'books' already exists: CREATE TABLE `books` (`id` bigint NOT NULL AUTO_INCREMENT PRIMARY KEY, `title` varchar(32) NOT NULL, `price` float, `subject_id` int, `description` text, `created_at` timestamp NULL) ENGINE=InnoDB /home/sania/library/db/migrate/20180407084831_books.rb:4:in `up'

原因:ActiveRecord::StatementInvalid: Mysql2::Error: 表“books”已存在:CREATE TABLE books (id bigint NOT NULL AUTO_INCRMENT PRIMARY KEY, title varchar(32) NOT NULL、price float、subject_id int、description 文本、created_at 时间戳 NULL) 引擎=InnoDB/home/sania/library/db/migrate/20180407084831_books.rb:4:in `up'

原因:

Mysql2::Error: Table 'books' already exists
/home/sania/library/db/migrate/20180407084831_books.rb:4:in `up'
Tasks: TOP => db:migrate

(通过使用 --trace 运行任务查看完整跟踪)

<小时/>

这是20180407084831_books.rb文件的内容

class Books < ActiveRecord::Migration[5.1]

def self.up
create_table :books do |t|
t.column :title, :string, :limit => 32, :null => false
t.column :price, :float
t.column :subject_id, :integer
t.column :description, :text
t.column :created_at, :timestamp
end
end

def self.down
drop_table :books
end

end
<小时/>

这是20180407072616_create_books.rb文件的内容

class CreateBooks < ActiveRecord::Migration[5.1]
def change
create_table :books do |t|

t.timestamps
end
end
end
<小时/>

请帮我解决问题。我是 Rails 新手。我也尝试过删除数据库,但 rakes 因以下错误而中止

rake 中止!ActiveRecord::NoEnvironmentInSchemaError:

架构中未找到环境数据。要解决此问题,请运行:

    bin/rails db:environment:set RAILS_ENV=development
<小时/>

我无法理解其原因。请帮我解释一下。提前致谢

最佳答案

回滚上次迁移

rake db:rollback

回滚 n 次迁移

rake db:rollback STEP=n

更多信息 here

如果您不需要上次迁移并且想要将其删除,您可以使用@fool-dev答案

关于mysql - rake 中止! StandardError : An error has occurred, 所有后续迁移均已取消:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49714492/

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