当前位置: 首页 > 知识库问答 >
问题:

迁移DB Rails时出错

艾昊明
2023-03-14

我试图使用这个迁移,但我不断地得到错误,就像下面这样

这是我的迁移文件

class CreateEmployees < ActiveRecord::Migration
  def self.up
    create_table :employees do |t|
      t.string :name 
      t.date :hiredate 
      t.float :salary 
      t.boolean :fulltime , :default => true 
      t.integer :vacationdays 
      t.text :comments
    end 
  end

  def self.down
    drop_table :employees
  end
end

SQLite3::SQLException:表“Employees”已存在:创建表“Employees”(“ID”整数主键AUTOINCREMENT NOT NULL,“name”varchar(255),“hiredate”date,“salary”float,“fulltime”boolean DEFAULT NOT“,”valationdays“INTEGER,”fulltime“boolean DEFAULT NOT”,“vacationdays”INTEGER,“comments”text)/library/ruby/gems/2.0.0/gems/sql y/gems/2.0.0/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:在中准备'/library/ruby/gems/2.0.0/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:134:在中执行'/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/activeRecord/connection_adapters/sqlite3_adapter.rb:328:在中块在.rb:425:inlog中的块'/library/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in仪器'/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:420:在日志'/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:328:在执行gems/activeRecord-4.0.0/lib/active_record/migration.rb:625:inmethod_missing“/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/active_record/migration”中的块。rb:597:insay_with_time“/library/ruby/gems/2.0.0/gems/active_record/migration中的块。rb:597:insay_with_time”/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/active_record/migration.rb:383:inmethod_missing'/users/yuriaguirre/documenTS/Aptana Studio 3 Workspace/company/db/migrate/20130923140626_create_employees.rb:3:inup'/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/activeRecord/migrate.rb:534:inup'/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/activeRecord/migrate.rb:574:in/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/active_record/migration.rb:554:在中的块在migrate'/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:在with_connection 709:inmigrate'/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/active_record/migration.rb:959:inblock in execute_migration_in_transaction'/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/activeRecord/connection_adapters/abstract/database_statements.rb:1005:in在ddl_transaction中的块。rb:202:in在transactio中的块y/gems/2.0.0/gems/activeRecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:在事务中'/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/activeRecord/transactions.rb:209:在事务中_migration_in_transaction'/library/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/migration.rb:920:在中的块migrate'/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/activeRecord/migration.rb:916:在中的每个'/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/activeRecord/migration.rb:916:在中的每个active_record/migration.rb:742:inmigrate'/library/ruby/gems/2.0.0/gems/activeRecord-4.0.0/lib/active_record/railties/databases.rake:42:in`block(2个级别)in'tasks:TOP=>db:migrate(请参阅通过运行任务与--trace进行完整跟踪)

共有1个答案

潘皓
2023-03-14

已经在数据库中创建了员工表。你需要修复它,然后你可以用两种方法1。删除数据库并创建多个或2个。运行向下迁移然后向上迁移

rake db:drop
rake db:create
rake db:migrate
 类似资料:
  • 你能帮助我们哪里错了或者需要做什么吗… 提前感谢…

  • 我基本上是在Crashlytics中遵循迁移指南(这篇文章对其进行了总结)。 我一字不差地遵循相同的说明,您可以从我的中看到: 然而,当我同步我的Gradle时,我得到了这个错误: 5:02 PM Gradle同步失败:找不到DefaultDependencyHandler类型org.gradle.api.internal.artifacts.dsl.dependencies.对象的参数[com.

  • 我刚刚通过Android Studio菜单选项Refactor->Refactor to androidx迁移到androidx 我得到以下错误: Android.View.InflateException:二进制XML文件行#2:二进制XML文件行#2:膨胀类AndroidX.ConstraintLayout.ConstraintLayout时出错 知道吗? 堆栈跟踪:

  • 我正在flyway的CMD中运行命令,但脚本文件的迁移会出现以下异常 [错误]无法执行目标组织。flywaydb:flyway maven插件:3.2.1:在convertopia auto db:org项目上迁移(默认cli)。flywaydb。果心应用程序编程接口。FlywayException:验证失败。迁移1.0.53的迁移描述不匹配[错误]- 我尝试过,它说构建成功,但问题仍然没有解决。

  • 我以前从未使用过antlr,但现在不得不将旧版本的语法迁移到最新版本。我正在尝试为C#目标生成lexer和解析器。我在迁移下面看到的开始规则上卡住了。 我得到以下错误。语法错误:

  • 我将Rails5与PostgreSQL一起部署,以便在Heroku中免费应用程序。这是我在中的配置: