create_table :categories, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t| t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin" end create_table :advertisers, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t| t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin" t.integer :category_id, limit: 8, null: false end create_table :affiliates, id: :bigint, options: "CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" do |t| t.string :name, limit: 250, null: true, charset: "utf8mb4", collation: "utf8mb4_bin" t.integer :category_id, limit: 8, null: false end add_index :advertisers, [:category_id], name: :index_advertisers_on_category_id add_index :affiliates, [:category_id], name: :index_affiliates_on_category_id add_foreign_key :advertisers, :categories, column: :category_id, name: :index_advertisers_on_category_id add_foreign_key :affiliates, :categories, column: :category_id, name: :index_affiliates_on_category_id