Heroku Rails 迁移问题

发布于 2024-10-24 17:30:06 字数 1683 浏览 2 评论 0原文

我现在在 git 中收到以下错误:

Home@PC /c/rails/konkurranceportalen (master)
    $ heroku rake db:migrate
    (in /app/x/home)
    ==  DeviseCreateAdmins: migrating =============================================
    -- create_table(:admins)
       -> 0.0148s
    -- add_index(:admins, :email, {:unique=>true})
       -> 0.0231s
    -- add_index(:admins, :reset_password_token, {:unique=>true})
    rake aborted!
    An error has occurred, this and all later migrations canceled:

    PGError: ERROR:  column "reset_password_token" does not exist
    : CREATE UNIQUE INDEX "index_admins_on_reset_password_token" ON "admins" ("reset
    _password_token")

    (See full trace by running task with --trace)

我已更改本地计算机上应用程序中的迁移文件。但当我使用 heroku rake db:migrate 时,它​​似乎没有改变任何东西。我已经运行 git push heroku master 。 我可以迁移本地计算机上的数据库。我目前正在使用 Mysql 和 phpmyadmin。

我是否必须更改我的database.yml,我的应用程序没有推送到heroku?

这是我的一些database.yml:

    production:
      adapter: mysql
      database: rails_p
      encoding: utf8
      pool: 5
      username: root
      password: 
      socket: C:/xampp/mysql/bin/mysqld.sock
      host: 127.0.0.1

我的迁移:

class DeviseCreateAdmins < ActiveRecord::Migration
  def self.up
    create_table(:admins) do |t|
      t.database_authenticatable :null => false
      t.rememberable
      t.timestamps
    end

    add_index :admins, :email,                :unique => true
    # add_index :admins, :confirmation_token,   :unique => true
    # add_index :admins, :unlock_token,         :unique => true
  end

  def self.down
    drop_table :admins
  end
end

I now get the following error in git:

Home@PC /c/rails/konkurranceportalen (master)
    $ heroku rake db:migrate
    (in /app/x/home)
    ==  DeviseCreateAdmins: migrating =============================================
    -- create_table(:admins)
       -> 0.0148s
    -- add_index(:admins, :email, {:unique=>true})
       -> 0.0231s
    -- add_index(:admins, :reset_password_token, {:unique=>true})
    rake aborted!
    An error has occurred, this and all later migrations canceled:

    PGError: ERROR:  column "reset_password_token" does not exist
    : CREATE UNIQUE INDEX "index_admins_on_reset_password_token" ON "admins" ("reset
    _password_token")

    (See full trace by running task with --trace)

I have changed the migration file in my app on my local machine. But it don't seem to change anything when I use heroku rake db:migrate. I have run git push heroku master.
I can migrate the database on my local machine. I am currently using Mysql with phpmyadmin.

Do I have to change my database.yml is my app not pushed to heroku?

Here is some of my database.yml :

    production:
      adapter: mysql
      database: rails_p
      encoding: utf8
      pool: 5
      username: root
      password: 
      socket: C:/xampp/mysql/bin/mysqld.sock
      host: 127.0.0.1

My migration:

class DeviseCreateAdmins < ActiveRecord::Migration
  def self.up
    create_table(:admins) do |t|
      t.database_authenticatable :null => false
      t.rememberable
      t.timestamps
    end

    add_index :admins, :email,                :unique => true
    # add_index :admins, :confirmation_token,   :unique => true
    # add_index :admins, :unlock_token,         :unique => true
  end

  def self.down
    drop_table :admins
  end
end

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

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

发布评论

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

评论(2

溺渁∝ 2024-10-31 17:30:06

错误可能发生在不同的迁移上,因为您没有包含 devise recoverable 列,并且您的脚本没有引用列 *reset_password_token*

您是否想要运行下面的脚本?

class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users) do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable   
      t.timestamps
    end

    add_index :users, :email,                :unique => true
    add_index :users, :reset_password_token, :unique => true
  end

  def self.down
    drop_table :users
  end
end

请记住,当您使用 heroku 时,您会推送 git 存储库,因此如果您有未提交的更改(如您所提到的),heroku 将不会看到它们。

It could be that the error is happening on a different migration, as you're not including devise recoverable column, and your script doesn't reference the column *reset_password_token*

Could it be that you want to run the following script?

class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users) do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable   
      t.timestamps
    end

    add_index :users, :email,                :unique => true
    add_index :users, :reset_password_token, :unique => true
  end

  def self.down
    drop_table :users
  end
end

Remember that when you use heroku you push your git repository, so if you have uncommitted changes (as you've mentioned), heroku won't see them.

往昔成烟 2024-10-31 17:30:06
git commit -a -m "updated some files"

然后 git Push heroku master

git commit -a -m "updated some files"

Then git push heroku master

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