I’m new to Rails and I’m trying to create an app using devise for the authentication part. The first thing I noticed was that my tests were failing because my users fixtures hadn’t an ID, so I put this on my User model
self.primary_key = :id
This helped my tests to run, but now I’m stuck on another problem. Everytime I try to add a user, the Devise controller fails with the following message:
ActiveRecord::StatementInvalid in Devise::RegistrationsController#create
SQLite3::ConstraintException: users.id may not be NULL: INSERT INTO "users" ("active", "created_at", "current_sign_in_at", "current_sign_in_ip", "default_business_id", "email", "encrypted_password", "first_name", "last_name", "last_sign_in_at", "last_sign_in_ip", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Why isn’t the User ID being created automatically? I’m running Devise 2 with Rails 3.2
Well, I finally found what the problem was. The
userstableidcolumn was not defined as a primary key in the DB, so that was the reason why Rails wasn’t assigning a value to it automatically. I don’t know how it happened, since I didn’t touch the migration that creates this table (this file is generated by Devise). Anyway, making a complete rollback and executing the migrations again fixed the problem. Thanks all who replied and hope this serves anyone in the future.