module 'django.db.models' has no attribute 'Foreignkey'

764 views
Skip to first unread message

Avitab Ayan Sarmah

unread,
Nov 20, 2018, 4:57:00 PM11/20/18
to Django users
Hi everyone,

I have written a code in models.py inside my project folder. I have completed my code and whenever i execute "python manage.py makemigrations first_app", i get an error. The error is mentioned as "AttributeError: module 'django.db.models' has no attribute 'Foreignkey'".

My code and my anaconda prompt error screenshot is attached below. Please check my code and give a resolution.
AP.PNG
MOdels.PNG

matteo gassend (LanguageMatt)

unread,
Nov 20, 2018, 4:59:26 PM11/20/18
to django...@googlegroups.com
the k in ForeignKey is Capitalized
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/78be7de9-f9c8-4501-a487-ad44e7824de9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Avitab Ayan Sarmah

unread,
Nov 20, 2018, 5:32:22 PM11/20/18
to Django users
Hi matteo,

Now it is showing as:

 File "C:\Users\AVITABAYAN\Desktop\django_lectures\first_project\first_app\models.py", line 11, in webpage
    topic = models.ForeignKey(Topic)
TypeError: __init__() missing 1 required positional argument: 'on_delete'

Please check :)

matteo gassend (LanguageMatt)

unread,
Nov 20, 2018, 5:36:10 PM11/20/18
to django...@googlegroups.com
A ForeignKey requires an “on_delete” argument. This is the function(kinda) that will be called when you decide to delete an instance of said model.

You can see it being used on the Django official tutorial,

Avitab Ayan Sarmah

unread,
Nov 20, 2018, 5:38:44 PM11/20/18
to django...@googlegroups.com
Thanks for your support. I will check and fix it. Thanks

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/XXBDDSFsqIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

matteo gassend (LanguageMatt)

unread,
Nov 20, 2018, 5:39:39 PM11/20/18
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages