Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Django model.py model.foreignkey()
#2
When you designate a field as a ForeignKey of another model Django will tie they field to whatever the primary key is of the parent table. When you run your migrate commands Django will create a column with the name of 'id' set it to primary and auto increment. That is what would happen in the scenario you have provided.
Reply


Messages In This Thread
Django model.py model.foreignkey() - by HenryJ - Feb-08-2018, 06:00 AM
RE: Django model.py model.foreignkey() - by DocSeussMan - Feb-09-2018, 04:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Django: View is unable to find attributes of database model pythonpaul32 1 726 May-20-2024, 05:38 AM
Last Post: tahirahmedd
  Querying Django model db - from Jose Portilla’s Udemy course Drone4four 2 1,801 Aug-09-2022, 09:25 AM
Last Post: Addweb
Photo After using models.Model on my class Im getting 'ImproperlyConfigured' error Django khavro 1 2,273 Apr-05-2021, 03:11 PM
Last Post: SheeppOSU
  Selenium Page Object Model with Python Cryptus 5 4,174 Aug-19-2020, 06:30 AM
Last Post: mlieqo
  [Django]calculate value in model smabubakkar 0 1,726 Apr-15-2020, 03:40 PM
Last Post: smabubakkar
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,454 Jun-30-2019, 12:21 AM
Last Post: scidam
  Need your help to fix my database relationship in Django model PrateekG 0 2,740 Jul-02-2018, 11:08 AM
Last Post: PrateekG
  Django not saving model in management command F2Andy 1 3,344 Jun-02-2018, 03:17 PM
Last Post: F2Andy
  How do I make a Django model from a tab-delimited data file? newbietostuff 0 2,579 Jan-09-2018, 02:44 AM
Last Post: newbietostuff
  Django field model for HTML parser? Drone4four 0 4,230 Nov-15-2017, 02:43 AM
Last Post: Drone4four

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020