Rails Postgres模式问题-以下模式之一无效:“ test”“ public”

迈克尔·希思

我已经在高低寻找了答案,但是我很快就提出了。

我正在尝试基于Postgres模式使用Rails 4,Devise和Apartment构建一个多租户应用程序。对于本地Postgres服务器,我决定使用PostgresApp。我遵循了Go Rails多租户指南,并且当该错误开始出现时,该设置(每个租户一个用户)正常工作。昨天,当我尝试为Devise安装Invitable扩展程序时,此消息开始在本地显示,但似乎找不到任何提示。

这是我得到特定错误的方法:

michael$ rake environment db:drop
michael$ rake db:create
michael$ rake db:migrate
== 20160908204559 DeviseCreateUsers: migrating ================================
-- create_table(:users)
   -> 0.0091s
-- add_index(:users, :email, {:unique=>true})
   -> 0.0032s
-- add_index(:users, :reset_password_token, {:unique=>true})
   -> 0.0031s
-- add_index(:users, :confirmation_token, {:unique=>true})
   -> 0.0032s
-- add_index(:users, :unlock_token, {:unique=>true})
   -> 0.0029s
== 20160908204559 DeviseCreateUsers: migrated (0.0219s) =======================

    [WARNING] - The list of tenants to migrate appears to be empty. This could mean a few things:

      1. You may not have created any, in which case you can ignore this message
      2. You've run `apartment:migrate` directly without loading the Rails environment
        * `apartment:migrate` is now deprecated. Tenants will automatically be migrated with `db:migrate`

    Note that your tenants currently haven't been migrated. You'll need to run `db:migrate` to rectify this.
michael$ rake db:seed
Seeding test tenant
One of the following schema(s) is invalid: "test" "public"

在本地访问该站点时,这会导致Rails抛出:

公寓:: TenantNotFound

以下架构之一无效:“ www”“ public”

这是我的apartment.rb初始化程序:

require 'apartment/elevators/subdomain'
Apartment.configure do |config|
  config.excluded_models = %w{ User }
  config.tenant_names = lambda { User.pluck :subdomain }
  config.use_schemas = true
end
Rails.application.config.middleware.use 'Apartment::Elevators::Subdomain'

这是我的用户迁移文件:

class DeviseCreateUsers < ActiveRecord::Migration
  def change
    create_table(:users) do |t|
      ## Database authenticatable
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""

      ## Recoverable
      t.string   :reset_password_token
      t.datetime :reset_password_sent_at

      ## Rememberable
      t.datetime :remember_created_at

      ## Trackable
      t.integer  :sign_in_count, default: 0, null: false
      t.datetime :current_sign_in_at
      t.datetime :last_sign_in_at
      t.string   :current_sign_in_ip
      t.string   :last_sign_in_ip

      ## Confirmable
      t.string   :confirmation_token
      t.datetime :confirmed_at
      t.datetime :confirmation_sent_at
      t.string   :unconfirmed_email # Only if using reconfirmable

      ## Lockable
      t.integer  :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
      t.string   :unlock_token # Only if unlock strategy is :email or :both
      t.datetime :locked_at

      ## Invitable
      #t.string   :invitation_token
      #t.datetime :invitation_created_at
      #t.datetime :invitation_sent_at
      #t.datetime :invitation_accepted_at
      #t.integer  :invitation_limit
      #t.integer  :invited_by_id
      #t.string   :invited_by_type

      ## User Info
      t.string :first_name
      t.string :last_name
      t.string :subdomain
      t.string :role

      t.timestamps
    end

    add_index :users, :email,                unique: true
    add_index :users, :reset_password_token, unique: true
    add_index :users, :confirmation_token,   unique: true
    add_index :users, :unlock_token,         unique: true
    #add_index :users, :invitation_token,     unique: true
  end
end

我还通过命令行进入了本地Postrgres数据库。放置正在工作,创建数据库正在工作。如果需要,我可以提供这些。目前,我的猜测是告诉我Rails与PostgresApp交流的方式或进行迁移的方式出了问题。但是也许有更多经验的人可以指出我想念的东西。

所以我的问题是我正在怎么做导致这种情况?我该如何解决?而且我如何才能更多地了解出了什么问题呢?

迈克尔·希思

好的,所以我终于解决了它。迁移时,架构之间似乎存在差异。由于某种原因,由于某种原因而未更新架构。我不完全确定为什么这可以解决问题,但是我所做的是进入租户类文件和迁移文件(在我的情况下为User.rb),然后注释掉除Devise所需的最低要求以外的所有内容。然后我一次跑了一个:

rake db:drop
rake db:create 
rake db:migrate

在迁移时,出现错误:

重复键值违反唯一约束“ index_users_on_email”

因此,然后我回过头,取消注释所有内容,然后重新运行rakes,并在这次包含rake db:seed。而且有效!

michael$ rake db:seed
Seeding test tenant
michael$ 

关于为什么会引发此错误,我的最佳猜测是:

  1. 旧的数据库架构以某种方式在两次删除之间仍然存在
  2. 新的schema.rb文件未更新,并且存在某种差异

无论哪种方式,看来这都是完美的风暴场景。如果可以重新创建,我会回发。如果发生这种情况,其他人将只关注模式,而不关注数据库,单元或设计。那应该节省您很多时间。我希望这对其他人有帮助。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Yeoman grunt测试模式“ path_public / todo / test / mock / ** / *。js”与任何文件都不匹配

来自分类Dev

如何在Rails生产模式下的/ public中压缩js,css文件

来自分类Dev

H2和oracle的dbunit模式问题,模式始终是PUBLIC

来自分类Dev

生产模式下的rails4和mongoid问题

来自分类Dev

Postgres创建数据库默认情况下将添加另一个模式以及public

来自分类Dev

Ruby on Rails设计模式

来自分类Dev

Ruby on Rails引导模式

来自分类Dev

Rails 5.2.3 / Heroku - 为什么不能在开发模式下使用 sqlite3 在生产模式下运行 postgres?

来自分类Dev

Rails Devise Bootstrap注册模式

来自分类Dev

策略模式文件位置Rails

来自分类Dev

修改URL模式Ruby Rails

来自分类Dev

Rails模型中的动态模式

来自分类Dev

Rails Devise Bootstrap注册模式

来自分类Dev

rails 5 有很多模式

来自分类Dev

For Each in rails html 模式延续

来自分类Dev

Instagram API-以沙箱模式接收public_content

来自分类Dev

熊猫to_sql除了PostgreSQL上的'public'不能写模式

来自分类Dev

在生产模式下启动Rails应用程序时出现设计问题

来自分类Dev

Postgres模式最佳实践

来自分类Dev

Postgres 从模式继承

来自分类Dev

解决模式无效(需要删除)的组合问题

来自分类Dev

如何定义可从任何模式调用而无需指定模式名称的 PUBLIC Oracle 函数?

来自分类Dev

rails csv导入ram消耗问题postgres

来自分类Dev

Rails迁移到Postgres问题(时间)

来自分类Dev

Public_activity gem参数Rails 3

来自分类Dev

Rails SQL复杂查询public_activity

来自分类Dev

Rails路线:如何根据模式匹配Rails路线

来自分类Dev

XML模式验证问题

来自分类Dev

BigDecimal舍入模式问题

Related 相关文章

热门标签

归档