Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails5-如何数据库:设置新机器并包括数据库自动增量id序列_Ruby On Rails_Postgresql_Activerecord_Migration_Ruby On Rails 5 - Fatal编程技术网

Ruby on rails Rails5-如何数据库:设置新机器并包括数据库自动增量id序列

Ruby on rails Rails5-如何数据库:设置新机器并包括数据库自动增量id序列,ruby-on-rails,postgresql,activerecord,migration,ruby-on-rails-5,Ruby On Rails,Postgresql,Activerecord,Migration,Ruby On Rails 5,我有一个从头开始构建的Rails5API和所有模型的数据库序列,用于自动创建id autoincrement。当一位同事试图在新机器上db:setup数据库时,加载了模式,但没有创建序列,因此,无法添加我们的db:seeds,因为表上存在“notnull”约束 原始表id列如下所示 id | integer | not null default nextval('users_id_seq'::regclass) | plain | id | integer | not null |

我有一个从头开始构建的Rails5API和所有模型的数据库序列,用于自动创建id autoincrement。当一位同事试图在新机器上db:setup数据库时,加载了模式,但没有创建序列,因此,无法添加我们的db:seeds,因为表上存在“notnull”约束

原始表id列如下所示

id  | integer | not null default nextval('users_id_seq'::regclass) | plain    |
id  | integer | not null  | plain    |
class CreateUsers < ActiveRecord::Migration[5.0]
  def change
    create_table :users do |t|
      t.string :first_name, limit: 25
      t.string :last_name, limit: 25
      t.string :mobile_phone, limit: 25
      t.string :auth_token, limit: 36
      t.integer :failed_login_attempts, limit: 2, :default => 0
      t.boolean :account_locked, :default => false
      t.timestamps
    end
  end
end
运行db:setup后,新机器上的“新”数据库如下所示

id  | integer | not null default nextval('users_id_seq'::regclass) | plain    |
id  | integer | not null  | plain    |
class CreateUsers < ActiveRecord::Migration[5.0]
  def change
    create_table :users do |t|
      t.string :first_name, limit: 25
      t.string :last_name, limit: 25
      t.string :mobile_phone, limit: 25
      t.string :auth_token, limit: 36
      t.integer :failed_login_attempts, limit: 2, :default => 0
      t.boolean :account_locked, :default => false
      t.timestamps
    end
  end
end
我以前的Rails版本从未遇到过这个问题,我想知道这是否是v5版本的问题。我们做错了什么

谢谢你的建议

在新数据库上,运行“\ds;”时,postgres中没有显示序列

users表的迁移如下所示

id  | integer | not null default nextval('users_id_seq'::regclass) | plain    |
id  | integer | not null  | plain    |
class CreateUsers < ActiveRecord::Migration[5.0]
  def change
    create_table :users do |t|
      t.string :first_name, limit: 25
      t.string :last_name, limit: 25
      t.string :mobile_phone, limit: 25
      t.string :auth_token, limit: 36
      t.integer :failed_login_attempts, limit: 2, :default => 0
      t.boolean :account_locked, :default => false
      t.timestamps
    end
  end
end

schema.rb
看起来像什么?@muistooshort。。我为上面这个特定的表添加了schema.rb。这个
id::integer
看起来是错误的还是至少可疑?我很久以前就切换到了
structure.sql
,因为我使用的东西ActiveRecord不懂,所以我敢肯定,但是
id::integer
对我来说味道不好。嗯,我的Rails4项目也不这么做。我不熟悉structure.sql,但将对此进行调查。有什么建议吗?我想知道你使用的Rails5版本是否有倒退。使用
structure.sql
而不是
schema.rb
非常简单(中有一个简短的提纲)。