ruby-on-rails - 在 postgresql 应用程序的 rails 中运行迁移后的序列通知

标签 ruby-on-rails ruby postgresql database-migration

当我在 postgresql 上的 Rails 应用程序中运行我的迁移时,我得到了以下通知

NOTICE:  CREATE TABLE will create implicit sequence "notification_settings_id_seq" for serial column "notification_settings.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "notification_settings_pkey" for table "notification_settings"

我的迁移文件包含 088_create_notification_settings.rb

class CreateNotificationSettings < ActiveRecord::Migration
  def self.up
    create_table :notification_settings do |t|
      t.integer :user_id
      t.integer :notification_id
      t.boolean :notification_on
      t.boolean :outbound
    end
  end

  def self.down
    drop_table :notification_settings
  end
end

我想知道

这个通知是什么意思?

如何避免此通知?

如果不避免此类通知,会对应用程序产生什么影响?

问候,

萨利尔

最佳答案

Rails(更准确地说是 ActiveRecord)正在向您的表中添加一个 id 列,并使该列成为主键。对于 PostgreSQL,此列的类型为 serialserial column本质上是一个四字节整数,结合一个序列以自动提供自动递增的值。

第一条通知:

NOTICE: CREATE TABLE will create implicit sequence "notification_settings_id_seq" for serial column "notification_settings.id"

只是告诉您 PostgreSQL 正在幕后创建序列以使 serial 列起作用。

第二条通知:

NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "notification_settings_pkey" for table "notification_settings"

只是告诉你 PostgreSQL 正在创建一个索引来帮助实现主键,即使你没有明确要求它这样做。

您可以忽略这些通知,它们只是提供信息。如果你想抑制它们,你可以添加 min_messages: WARNINGdatabase.yml 的适当部分。

关于ruby-on-rails - 在 postgresql 应用程序的 rails 中运行迁移后的序列通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5296290/

相关文章:

java - 在Java Android应用程序中获取ruby环境变量DATABASE_URL

ruby-on-rails - 在 Ruby on Rails 中, '#encoding: utf-8' 和 'config.encoding = "utf-8"' 是否不同?

ruby-on-rails - ActiveAdmin 自定义选择过滤器下拉名称

ruby - 如何从 ruby​​ 中的字符串中删除所有非数字?

ruby-on-rails - 错误:执行 gem 时 ... (Gem::Package::FormatError) profile.gem 中缺少包元数据

sql - 戈朗 pq : syntax error when executing sql

postgresql - 大数据集(PostgreSQL)中行中的列——转置?

ruby-on-rails - rails : simple_form association with i18n

postgresql - PostgreSQL中一行中窗口函数的第一个和最后一个值

ruby - 此 ruby​​ 代码算作递归函数吗?