【问题标题】:rake db:migrate issue postgresqlrake db:迁移问题 postgresql
【发布时间】:2013-09-07 10:50:35
【问题描述】:

我完全是 PostgreSQL 的菜鸟,Ruby on Rails..

我正在尝试学习本教程(没有 ruby​​mine)http://www.codeproject.com/Articles/575551/User-Authentication-in-Ruby-on-Rails#InstallingRubyMine4

我有这样的迁移(001_create_user_model.rb):

class CreateUserModel < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.column :username, :string
      t.column :email, :string
      t.column :password_hash, :string
      t.column :password_salt, :string
    end
  end

  def self.down
    drop_table :users
  end
end

我得到的错误是这样的:

syntax error, unexpected ':', expecting ';' or '\n'
        t.column...sers do |t|

...
C:131071:in 'disable_dll_transaction'
Task:TOP => db:migrate

【问题讨论】:

  • 那是你那里的一些非常古老的语法......看起来不像一个好的教程。
  • 嗯,我也尝试了下面的语法。没用,同样的错误。

标签: ruby-on-rails ruby postgresql dbmigrate


【解决方案1】:

这个呢:

class CreateUserModel < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.string :username, :null => false
      t.string :email,:null => false
      t.string :password_hash, :null => false
      t.string :password_salt, :null => false
      t.timestamps
    end
  end

  def self.down
    drop_table :users
  end
end

【讨论】:

  • 除了文字差异?我刚刚挑选了一个随机迁移并将其转换为该格式。不确定 Ahmad 的迁移是否来自旧版本的 Rails。
  • 不是文字差异。根据 ActiveRecord::Migration 文档,他的代码仍然有效。您的答案应该是“您也可以将列类型用作方法调用,而不是调用列方法。”但它并没有从代码视图中解决问题。
  • 值得一试,FWIW。此外,我们没有太多事情要做。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-05
  • 1970-01-01
  • 2014-02-13
  • 1970-01-01
  • 2013-02-01
  • 2012-11-17
相关资源
最近更新 更多