Last active
August 29, 2015 14:17
-
-
Save kimegede/3c5775857d9c0ab189d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CreateZipcodes < ActiveRecord::Migration | |
| def change | |
| create_table(:zipcodes, id: false) do |t| | |
| t.integer :zipcode, primary_key: true | |
| t.string :city | |
| t.string :street | |
| t.string :company | |
| t.boolean :provins | |
| t.integer :country | |
| t.timestamps null: false | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CreateResidences < ActiveRecord::Migration | |
| def change | |
| create_table :residences do |t| | |
| t.string :name | |
| t.string :address | |
| t.belongs_to :zipcode, index: true | |
| t.timestamps null: false | |
| end | |
| add_foreign_key :residences, :zipcodes | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Mysql2::Error: Cannot add foreign key constraint: ALTER TABLE `residences` ADD CONSTRAINT `fk_rails_e76d45279d` | |
| FOREIGN KEY (`zipcode_id`) | |
| REFERENCES `zipcodes` (`id`) |
Author
@completit it works now, it was the space after create_table (:zipcodes.... there made the mistake.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try
create_table :zipcodes do |t|Without
id: false