NOTICES for sequence after running migration in rails on postgresql Application

喜欢而已 提交于 2019-12-17 17:55:16

问题


When i run my migration in Rails application on postgresql i got following NOTICES

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"

My migration file contains 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

I would like to know

what this NOTICES means?

How to avoid this NOTICES?

What will be the impact of such NOTICES on the Application if not avoided?

Regards,

Salil


回答1:


Rails (ActiveRecord to be more precise) is adding an id column to your table and making this column the primary key. For PostgreSQL, this column will have type serial. A serial column is essentially a four byte integer combined with a sequence to automatically provide auto-incrementing values.

The first notice:

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

is just telling you that PostgreSQL is creating a sequence behind the scenes to make the serial column function.

The second notice:

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

is just telling you that PostgreSQL is creating an index to help implement the primary key even though you didn't explicitly ask it to.

You can just ignore these notices, they're just informational. If you want to suppress them, you can add min_messages: WARNING to the appropriate section of your database.yml.




回答2:


In addition to what mu has said:

If you don't want to see those notices, you can turn them off by setting client_min_messages to warning (or error).

This can be done on session level, using set client_min_messages = warning or in the server's config file for all connections:

http://www.postgresql.org/docs/current/static/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHEN




回答3:


NOTICES are related to the creation of the sequence and the way that Postgresql creates the autoincrement on the id column.

To answer the other questions:

How to avoid NOTICES

In the database.yml file simply include min_messages: warning #magic sauce

What will be the impact on the application if NOTICES are ignored.

Basically it's going to increase the logging, especially if running in Development mode.

See http://www.ruby-forum.com/topic/468070 for more details



来源:https://stackoverflow.com/questions/5296290/notices-for-sequence-after-running-migration-in-rails-on-postgresql-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!