Tag: 迁移

如何在Ruby on Rails ActiveRecord迁移中处理太长的索引名称?

我试图添加一个从四个相关表的外键创建的唯一索引: add_index :studies, [“user_id”, “university_id”, “subject_name_id”, “subject_type_id”], :unique => true 数据库对索引名称的限制会导致迁移失败。 这是错误消息: 表’研究’上的索引名称’index_studies_on_user_id_and_university_id_and_subject_name_id_and_subject_type_id’太长; 限制为64个字符 我怎么处理这个? 我可以指定不同的索引名称吗?

heroku运行rake db:migrate – / bin / sh:1:rake:not found

当我试图运行heroku run rake db:migrate从Heroku代码 heroku run rake db:migrate = H10 desc =“App崩溃” – 无法弄清楚为什么它崩溃我得/bin/sh: 1: rake: not found – git push heroku master # if not done – heroku run rake db:migrate – heroku restart 有什么建议? 命令日志: 2017-07-08T23:10:22.242114+00:00 app[api]: Starting process with command `rake db:migrate` by user myname@gmail.com 2017-07-08T23:10:36.592694+00:00 heroku[run.1110]: Awaiting client 2017-07-08T23:10:36.631698+00:00 heroku[run.1110]: Starting […]

迁移以创建默认值

所以我想知道我们是否可以编写一个新的迁移来设置已经创建的字段的默认值。 我知道如何编写旧的迁移编辑并设置其默认值。 我想这样做是因为我做了很多迁移,现在我无法回滚并编辑该文件。 而且,有没有办法回滚到特定的迁移? 提前致谢

Rails:通过迁移填充现有表

假设我在Rails中有一个现有的迁移: class CreateStudies < ActiveRecord::Migration def change create_table :studies do |t| t.string :display_name, null: false t.string :tag_name, null: false t.timestamps end add_index :studies, :tag_name, unique: true end end 后来我意识到我想用多行填充这个表,我不想使用rake db:rollback或seeds.rb文件。 新迁移文件的格式是什么?

heroku:运行rake db:migrate错误

Running `rake db:migrate` attached to terminal… failed ! Multiple apps in folder and no app specified. ! Specify app with –app APP. 当我尝试运行rake db时,我的终端出现上述错误:迁移有人可以帮忙吗?

从schema.rb生成迁移文件

我想从schema.rb生成一个迁移文件。 可能吗? 我目前有许多迁移文件,并希望将所有内容合并到一个主迁移文件中。 我也认为我可能在某些时候意外删除了一个迁移文件。 谢谢你的帮助

如何配置额外/不同的迁移文件夹

我和一位同事正在分享一些模型的不同项目。 所以,我们通过git子模块共享模型。 此外,我们希望能够共享迁移: 通过这种方式,我的同事的迁移将位于我的项目的db/migrate/other_db文件夹中。 如何配置rails迁移以在此额外文件夹中运行迁移?

多态关联

如果你有多态的belongs_to关联,那么引用将添加所需的两个列: create_table :products do |t| t.references :attachment, :polymorphic => {:default => ‘Photo’} end 将添加一个attachment_id列和一个字符串attachment_type列,其默认值为“Photo”。 这到底是什么意思?

Rails 3 – has_and_belongs_to_many

我有2个模特 – 老师和主题 。 想要通过名称Qualification连接表连接它们。 看起来我做错了什么: class Teacher “Qualification” end class Subject “Qualification” end 我的迁移: class CreateQualificationJoinTable false do |t| t.integer :subject_id t.integer :teacher_id end add_index :qualification, :subject_id add_index :qualification, :teacher_id end end 例如,当我打开rails console并打印时 ruby-1.9.3-head :013 > Qualification 我明白了: NameError: uninitialized constant Qualification from (irb):13 from /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/railties-3.2.0/lib/rails/commands/console.rb:47:in `start’ from /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/railties-3.2.0/lib/rails/commands/console.rb:8:in `start’ from /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/railties-3.2.0/lib/rails/commands.rb:41:in `’ […]

从war文件中运行rake任务

我的代码库最初是用ruby编写的。 它有一个rakefile.rb文件来执行数据库迁移。 之后我将整个事情改为jruby,以便于部署,并且工作正常。 我面临的唯一问题是如何运行我的rake任务(执行数据库迁移)。 我试过了 java -jar GV_S.war -S rake db_migrate[1] 1是版本,但这不起作用。 这给了我: [Winstone 2012/03/23 18:04:56] – Beginning extraction from war file [Winstone 2012/03/23 18:04:56] – WARNING: The Servlet 2.4/2.5 spec XSD was unavailable inside the winstone classpath. Will be retrieved from the web if required (slow) [Winstone 2012/03/23 18:04:56] – No webapp classes folder […]