rake :db migrate 不返回任何内容

发布于 2024-10-10 15:47:22 字数 914 浏览 0 评论 0原文

我创建了一篇模型文章并在 001_create_articles.rb 中添加了以下代码

class CreateArticles < ActiveRecord::Migration
  def self.up
create_table :articles do |t|
    t.string :title
    t.text   :body
    t.string :published_at

    t.timestamps
end
  end
def self.down
drop_table :articles
end
end

然后我尝试运行

 rake db:migrate --trace
I dint get any output, the console just blinks for a minute. The output of the rake is

C:\InstantRails-2.0-win\rails_apps\blog>rake db:migrate --trace
(in C:/InstantRails-2.0-win/rails_apps/blog)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
** Invoke db:schema:dump (first_time)
** Invoke environment
** Execute db:schema:dump

另外rake:db migrate在我的任何项目中都不起作用

此外Mysql服务器正在运行并且我能够登录到服务器。我的database.yml 文件没问题。

这是配置问题还是我遗漏了什么?

i created a model Article and addedd the following code in 001_create_articles.rb

class CreateArticles < ActiveRecord::Migration
  def self.up
create_table :articles do |t|
    t.string :title
    t.text   :body
    t.string :published_at

    t.timestamps
end
  end
def self.down
drop_table :articles
end
end

Then i tried running

 rake db:migrate --trace

I dint get any output, the console just blinks for a minute.
The output of the rake is

C:\InstantRails-2.0-win\rails_apps\blog>rake db:migrate --trace
(in C:/InstantRails-2.0-win/rails_apps/blog)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
** Invoke db:schema:dump (first_time)
** Invoke environment
** Execute db:schema:dump

also rake :db migrate is not working in anyof my projects

Also Mysql server is running and i am able to login to the server. my database.yml file is fine.

Is this a configuration issue or i am missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梅倚清风 2024-10-17 15:47:22

您的数据库有一个 schema_migrations

如果文件已经运行,版本号将在那里,您可以删除该数据库中的条目并运行 db:migrate,请注意,它可能也会删除您的所有数据。

如果您想对数据库进行增量更改而不修改数据,您可以创建一个新的迁移来修改现有的数据库结构,例如:

note that you need to do this in a new migration file.
class AddAttachmentCxpp1ToCustomer < ActiveRecord::Migration
  def self.up
    add_column :customers, :cxpp1_file_name, :string
    add_column :customers, :cxpp1_content_type, :string
    add_column :customers, :cxpp1_file_size, :integer
    add_column :customers, :cxpp1_updated_at, :datetime
  end

  def self.down
    remove_column :customers, :cxpp1_file_name
    remove_column :customers, :cxpp1_content_type
    remove_column :customers, :cxpp1_file_size
    remove_column :customers, :cxpp1_updated_at
  end
end

Your database has a schema_migrations

if the file has already been run the version number will be there, you can remove the entries in that DB and run db:migrate, note that it will probably remove all your data as well.

if you want to make an incremental change to the db without modifying the data you can create a new migration that modifies the existing database structure an example:

note that you need to do this in a new migration file.
class AddAttachmentCxpp1ToCustomer < ActiveRecord::Migration
  def self.up
    add_column :customers, :cxpp1_file_name, :string
    add_column :customers, :cxpp1_content_type, :string
    add_column :customers, :cxpp1_file_size, :integer
    add_column :customers, :cxpp1_updated_at, :datetime
  end

  def self.down
    remove_column :customers, :cxpp1_file_name
    remove_column :customers, :cxpp1_content_type
    remove_column :customers, :cxpp1_file_size
    remove_column :customers, :cxpp1_updated_at
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文