Django Add A related_name argument to the Definit

Source: Internet
Author: User
Here's a one-to-many relationship model

Class Cats (models. Model):

#...

Catnum = models. Integerfield (Unique=true)

#...


Class Items (models. Model):

CATID = models. ForeignKey (Cats, to_field= ' catnum ', db_column= ' catid ')

#...

Unhandled exception in thread started by

Traceback (most recent):

File "c:\python27\lib\site-packages\django\core\management\commands\runserver.py", line +, in Inner_run

Self.validate (Display_num_errors=true)

File "c:\python27\lib\site-packages\django\core\management\base.py", line 253, in validate

Raise CommandError ("one or more models do not validate:\n%s"% error_text)

Django.core.management.base.CommandError:One or more models do not validate:

Beauty.items:Reverse Query name for field ' CATID ' clashes with field ' Cats.items '. Add a related_name argument to the Definit

Ion for ' catid '.

The error that occurred probably meant to add a related_name parameter, so the items model was changed to


Class Items (models. Model):

CATID = models. ForeignKey (Cats, to_field= ' catnum ', db_column= ' catid ', related_name= ' catid ')

#...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.