Django Developers Help Out With This Error - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Django Developers Help Out With This Error (1139 Views)
| Django Developers Help Out With This Error by sparkle7(op): 8:08am On Jun 04, 2019 |
Am getting intergrity error on django. Can you guys help identify the problem.
|
| Re: Django Developers Help Out With This Error by ogunsinamayowa(m): 8:23am On Jun 04, 2019 |
The error is telling you that you failed to provide input for a field that could not be null in the database. The field is author_id. |
| Re: Django Developers Help Out With This Error by sparkle7(op): 8:41am On Jun 04, 2019 |
ogunsinamayowa:But i thought the author id is auto incremented? |
| Re: Django Developers Help Out With This Error by kingkuntaval: 10:09am On Jun 04, 2019 |
use stackoverflow. |
| Re: Django Developers Help Out With This Error by Badilstical(m): 10:40am On Jun 04, 2019 |
First I'd ask you what did you do last while it was working fine? I would probably guess you added a property to your model, if that's the case you have to delete your migration and manage.py makemigration and then migrate BUT NOTE: Only of you on development on production you might loss you database Try that if it works let us know here |
| Re: Django Developers Help Out With This Error by ogunsinamayowa(m): 10:52am On Jun 04, 2019 |
sparkle7:Yes and no. In your case, because you want to override the django inbuilt object instance id, you need to put primary_key=True on the field of author_id and it would automatic. You need to populate the field and it cannot be null. I couldn't see author_id field in your model. Perhaps, you have deleted the field without updating the database(makemigrations). |
| Re: Django Developers Help Out With This Error by Nobody: 2:34pm On Jun 04, 2019 |
Try importing get_user_model from django.contrib.auth and replacing settings.AUTH_USER_MODEL with get_user_model(). You're probably getting the issue cause you didnt set settings. AUTH_USER_MODEL |
| Re: Django Developers Help Out With This Error by rammyblog: 2:17pm On Jun 05, 2019 |
The error is in your views.py file The post_new function is where the issue lies. The reason you are getting the error is because whenever you want to save a new post, the author id is set as NULL which is not supposed to be. To solve the issue where you had post = form.save(commit='false') Change it to post = form.save(commit=False) False should be a boolean value type not a string.. Hope that helps.. Contact me on fb for questions regarding Django fb.com/onasanyatunde |
Android Developers Help Me Out • Python Django Developers Circle • Hire Django Developers: Freelancers Vs Agencies • 2 • 3 • 4
Python Real World Application • Form Submitting To Email • Shop All UK & USA 2020 10-70% Off From Nigeria - Registration Is FREE