database - Ruby on Rails - Getting "Mysql2::Error: Unknown column" for one to many relationship -


i have 2 models, model_1 , model_2.

model_1.rb:

has_many :model_2s 

model_2.rb:

belongs_to :model_1 

but when try @model_1.model_2s following error:

actionview::template::error (mysql2::error: unknown column 'model_2.model_1_id' in 'where clause': select `model_2`.* `sketches` (`model_2s`.model_1_id = 1)) 

i have same problem using sqlite3. in advance help.

the has_many default relies on conventions.

has_many :model_2s

would use column "model_1_id" in "model_2" table default find "model_1" belongs (hey, chose name of models ;)). seem missing column.

for reasons unknown (unless provide migration files) table missing column.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -