I have a model called Issue
that has the following database structure :
class CreateIssues < ActiveRecord::Migration
def change
create_table :issues do |t|
t.string :path, null: false
t.string :filename, null: false
t.string :name, null: false
t.string :year
t.integer :number
t.timestamps null: false
end
end
end
In my model tests, I use the following line :
issue = Issue.create path: "test_path", filename: "test_filename", name: "test_name"
... which raises an exception when saving :
SQLite3::ConstraintException: NOT NULL constraint failed:
issues.path: INSERT INTO "issues" ("created_at", "updated_at") VALUES (?, ?)
From what I understand, when calling create
or new/save
, rails starts by inserting an entry with only the timestamps. I would expect the insert to contain all of the values that I have passed to the create
method. Am I missing a step in the creation process?
EDIT :
Basic information and steps:
- Using SQLite3
- Using Rails 4.2.1
- Using RSpec
- Generated the Issue model using
be rails generate model Issue
- Added the
NULL
constraints afterwords by hand - Did
be rake db:migrate
successfully - Tried my code in various model spec files
Tried other models, I get generated SQL that only includes the timestamps.
EDIT 2: Here is my Issue model :
class Issue < ActiveRecord::Base
has_one :pending_issue
has_one :watched_issue
has_many :unmatched_issues
validates :path, presence: true
validates :filename, presence: true
validates :name, presence: true
attr_accessor :path
attr_accessor :filename
attr_accessor :name
attr_accessor :year
attr_accessor :number
end