Error PG::Error: ERROR: null value in column "trust_level" violates not-null constraint

(Michael - #1

When checking out latest from Github an error occurs:

==  RenameSystemUsername: migrating ===========================================
-- execute("update site_settings set name = 'site_contact_username' where name = 'system_username'")NOTICE:  ALTER TABLE / ADD PRIMARY KEY will create implicit index "user_stats_pkey" for table "user_stats"
rake aborted!
PG::Error: ERROR:  null value in column "trust_level" violates not-null constraint
: INSERT INTO "users" ("active", "admin", "approved", "approved_at", "approved_by_id", "auth_token", "auto_track_topics_after_msecs", "banned_at", "banned_till", "bio_cooked", "bio_raw", "blocked", "created_at", "date_of_birth", "days_visited", "digest_after_days", "dynamic_favicon", "email", "email_digests", "email_direct", "email_private_messages", "enable_quoting", "external_links_in_new_tab", "flag_level", "id", "ip_address", "last_emailed_at", "last_posted_at", "last_seen_at", "likes_given", "likes_received", "moderator", "name", "new_topic_duration_minutes", "password_hash", "posts_read_count", "previous_visit_at", "salt", "seen_notification_id", "time_read", "title", "topic_reply_count", "topics_entered", "trust_level", "updated_at", "uploaded_avatar_id", "uploaded_avatar_template", "use_uploaded_avatar", "username", "username_lower", "views", "website") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $50, $51, $52) RETURNING "id"

Did anything change in the way a new forum is installed, or is this a bug…?

(Michael - #2

Done some more investigation.

  • This seems to be a multisite issue.
  • Running bundle exec rake multisite:migrate solves the problem for one database. So if you have a multisite host with 5 databases, you have to run multisite:migrate six times and then you’re ok. It crashes but apparently it paves the road for the next attempt to go right. So it seems like there is something in the wrong order regarding the migrations.

It’s very weird that this doesn’t happen with a single site setup though.

It seems like this is actually the same problem, it also mentions how running multisite:migrate needs to be ran twice.

  1. run RUBY_GC_MALLOC_LIMIT = 90000000 RAILS_ENV = production bundle
    exec rake multisite: migrate. Give a mistake at the end. 7) re-run the
    previous step and finish without problems impact.

Just checking a few assumptions around multisite:migrate, trying to understand better what is going on, can someone please confirm or correct?

  • db:migrate runs db:seed_fu as well, right? No need to run that separately?

  • multisite:migrate runs db:migrate for each site, right?

  • given the above two assumptions, multisite:migrate runs db:seed_fu for each site as well, right? (So that would mean that the instructions here are not correct?)

(Sam Saffron) #3

multisite migrate runs

task "multisite:migrate" => :environment do
  RailsMultisite::ConnectionManagement.each_connection do |db|
    puts "Migrating #{db}"
    puts "---------------------------------\n"
    t = Rake::Task["db:migrate"]

I suspect we need to shell out to run the migrates cause there is some shared state that is not being cleared.

Additionally longer term out migrations should never touch active record models (nor should seed_fu) cause it makes migrations fragile.

(Jeff Atwood) #4

Is this still an issue or can it be closed?

(Michael - #5

I’ve never encountered this problem again after we moved away from that specific version. It seems to have been one specific migration.

(Jeff Atwood) #6