---
title: "Discussion on \"Rails add foreign key\" | Hashnode"
description: "Discussion on \"Rails add foreign key\". when we want to add a foreign key in Rails\nwe can run this command\nbin/rails g migration add_author_to_books author:references\n\nthis means one author has one or more books in the database\nclass AddAuthorToBooks < ActiveRecord::Migration[7.0]\n  def ch..."
url: "https://hashnode.com/posts/rails-add-foreign-key/638756ee8b7b2fc48626f8c5"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Rails add foreign key](https://lihua.hashnode.dev/rails-add-foreign-key?utm_source=hashnode&utm_medium=feed)

when we want to add a foreign key in Rails we can run this command bin/rails g migration add\_author\_to\_books author:references this means one author has one or more books in the database class AddAuthorToBooks < ActiveRecord::Migration\[7.0\] def ch...

Nov 30, 2022 · 1 min read · lihua.hashnode.dev  
Updated Dec 4, 2022  
Read the article

## Written by

[Xin shen](https://hashnode.com/@lihua)

@lihua · China Beijing

  
[View profile](https://hashnode.com/@lihua)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
