What is the difference between a primary key and a foreign key? Where would we find a primary key? What would it be called by default? Where would we find a foreign key? What is the naming convention for a foreign key?
A primary key is the primary unique identifier of a table, a foreign key is the primary key of another table that serves as as the relationship between the two tables. A primary key is generally named id, a foreign key is named othertable_id whith the name of the table the foriegn key links to followed by id.
- a
one-to-one
relationship.- Each car has one license plate and each license plate belongs to one car
- a
one-to-many relationship
.- A School has many students but each student has only one school
- a
many-to-many relationship
.- A teacher has many students a student has many teachers
test databases are used only for your test, development databases for while you are in development of your app, and production as your live deployed database
rails new app_name --database=postgresql
It made our model file, our migration file with the table being created with all columns specified by arguments. It also generated a model test and fixtures file