I am having these ProgrammingErrors occurring on my production server lately. The page which the user is submitting a form at is a UserCreateView and is being redirected to the phone-verification page. The error reads:
Internal Server Error: /phone-verification/
ProgrammingError at /phone-verification/
column quiz_sitting.percent_correct does not exist
LINE 1: ...rrect_questions", "quiz_sitting"."current_score", "quiz_sitt...
^
I am not sure why its looking at quiz_sitting in the database because /phone-verification/ has nothing to do with that. The view for /phone-verification/ looks like this:
#login_required
def phone_verify_check(request):
employee = request.user
phone_verify, _ = PhoneVerify.objects.get_or_create(employee=employee)
login_tracker = EmployeeLogin.objects.create(employee=employee, ip_address=get_client_ip(request))
login_tracker.save()
if phone_verify.verified:
return redirect('dashboard')
else:
return redirect('resend')
I am using Django tenant schemas for handling subdomains which means when I run a migration it looks like:
python manage.py makemigrations
python manage.py migrate_schemas --shared
python manage.py migrate_schemas --tenant
I recently deleted all my migrations because I was having these ProgrammingErrors on another page and then I ran the makemigrations etc again and it seemed to have fix it. But now it is occurring again. I really hope there isn't some sort of corruption in the database like columns being mixed up. Any help is greatly appreciated!
My website is working well on my local environment, as well as it has been working well on heroku env until my recent deployment.
Code is same on both environments and I referred to all 11 posts related to similar issue,example Reverse for 'todo-user' with arguments '('',)' not found. 1 pattern(s) tried
My issue looks different than what I have seen in other posts here, I think it is related to environment settings/variables, which I am not able to identify it yet.
But the solutions provided on stack overflow, makes me think like the real problem of this issue is something else.
When I try to click on http://127.0.0.1:8000/catalog/mybooks/ link, local website works fine, however, production (heroku), same code throws following exception
NoReverseMatch at /catalog/mybooks/
Reverse for 'book-detail' with arguments '('',)' not found. 1 pattern(s) tried: ['catalog/book/(?P<pk>[0-9]+)$']
Request Method: GET
Request URL: https://<myapp>.herokuapp.com/catalog/mybooks/
Django Version: 2.2.5
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'book-detail' with arguments '('',)' not found. 1 pattern(s) tried: ['catalog/book/(?P<pk>[0-9]+)$']
Exception Location: /app/.heroku/python/lib/python3.7/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 673
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.7.3
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python37.zip',
'/app/.heroku/python/lib/python3.7',
'/app/.heroku/python/lib/python3.7/lib-dynload',
'/app/.heroku/python/lib/python3.7/site-packages']
Server time: Wed, 9 Oct 2019 04:52:47 +0000
Error during template rendering
In template /app/catalog/templates/base_generic.html, error at line 7
Reverse for 'book-detail' with arguments '('',)' not found. 1 pattern(s) tried: ['catalog/book/(?P<pk>[0-9]+)$']
This looks like a misleading error to me.
Also, because the code is working as expected on my local (ie, showing me all the data), so it doesn't look like a coding issue and so I am not able to understand real problem here (and provided solutions for other similar issues)
I have applied all migrations, so environment looks okay:
$ heroku run python manage.py migrate --remote heroku-prod
Running python manage.py migrate on <my app>... starting, run.5216 (Free)
Running python manage.py migrate on <my app>... connecting, run.5216 (Free)
Running python manage.py migrate on <my app>... up, run.5216 (Free)
Operations to perform:
Apply all migrations: admin, auth, catalog, contenttypes, sessions, social_django
Running migrations:
No migrations to apply.
HP#HP-PC MINGW64 ~/git_projects/prod/django_local_library (master)
Code on DEV/staging, that is also same.
Code:
urls.py for links related to book
urlpatterns = [
path('books/', views.BookListView.as_view(), name='books'),
path('book/<int:pk>', views.BookDetailView.as_view(), name='book-detail'),
path('mybooks/', views.LoanedBooksByUserListView.as_view(), name='my-borrowed'),
]
views.py
class BookDetailView(LoginRequiredMixin, generic.DetailView):
model = Book
def get_context_data(self, **kwargs):
context = super(BookDetailView, self).get_context_data(**kwargs)
process_data(self.request)
return context
class LoanedBooksByUserListView(LoginRequiredMixin, generic.ListView):
"""Generic class-based view listing books on loan to current user. """
model = BookInstance
template_name = 'catalog/bookinstance_list_borrowed_user.html'
def get_queryset(self):
return BookInstance.objects.filter(borrower=self.request.user).filter(status__exact='o').order_by('due_back')
def get_context_data(self, **kwargs):
context = super(LoanedBooksByUserListView, self).get_context_data(**kwargs)
process_data(self.request)
return context
Template
{% for bookinst in bookinstance_list %}
<li class="{% if bookinst.is_overdue %}text-danger{% endif %}">
{{bookinst.book.title}} ({{ bookinst.due_back }})
</li>
{% endfor %}
Yesterday night, after this post, I turned off DEBUG for security purpose, ie set DEBUG=False for staging env, as well as for local and added host on ALLOWED_HOSTS, local and staging work fine, however prod is throwing 500 error:
FYI: staging and prod have same configurations, except host name
Ref Setting DEBUG = False causes 500 Error
If I rollback to previous committed code, it starts throwing error highighted in this ques
And if I verify directly on heroku
HP#HP-PC MINGW64 ~/git_projects/prod/django_local_library (master)
$ heroku run python manage.py runserver --remote heroku-prod
It doesn't throw any exception:
Performing system checks...
System check identified no issues (0 silenced).
October 09, 2019 - 21:18:54
Django version 2.2.5, using settings 'locallibrary.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Even the staging logs have no error.
Please help me if someone has ever faced any such issue.
Solution to my problem was fixed when I followed What is a NoReverseMatch error, and how do I fix it? and NoReverseMatch django - not a valid view function or pattern
And I think all such/similar issues should point to the above link.
Root cause:
Data was corrupted, I deleted corrupted data, and the issue was fixed without any change in the code.
Steps:
I faced similar issue for another new page that I added recently, but the root cause was different (it was due to url formed was incorrect), and the above link helped me identifying the real cause of this issue. I carefully looked into details, including url formed and the page from where url was being referred and finally the data.
And the website currently looks like this https://www.realityseekers.com/
Same problem to me.
All the things were fine except the contents in the table bookinstances.
Somehow, there were several rows in bookinstances misleading, and that rows had not the correspondet row at the table books...
There were bookinstances without books, and when the view tries to get the data, the for bucle got nothing, and when the code: {% url 'book-detail' bookinst.book.pk %}"
tries to do the reverse of nothing, all the things go wrong...
But the dissapointing thing here, is that this kind of error should be best interpreted by Django.
I am currently upgrading a Django 1.9 site to use Django 1.10. I would love to upgrade to Django 1.11, but some of the packages the site uses do not yet support it.
Either way, I am getting the following error when I go to localhost:8000
FieldError at /
'content' cannot be specified for Article model form as it is a
non-editable field
Request Method: GET Request URL: http://localhost:8000/ Django
Version: 1.10.9 Exception Type: FieldError Exception Value:
'content' cannot be specified for Article model form as it is a
non-editable field
Exception Location:
/xxx-env/lib/python3.6/site-packages/django/forms/models.py in
fields_for_model, line 143
The site is running Django CMS 3.4.4, as well as other Aldryn Plugins, all of which are up-to-date using pip install.
The code in question is this:
if (fields is not None and f.name in fields and
(exclude is None or f.name not in exclude)):
raise FieldError(
"'%s' cannot be specified for %s model form as it is a non-editable field" % (
f.name, model.__name__)
)
continue
I would love some tips or directions on how I could troubleshoot this.
I was able to overcome the bug by installing the latest master version of aldryn-newsblog with:
pip install git+https://github.com/aldryn/aldryn-newsblog.git#master
You may also watch the discussion from here or here.
I am developing app that uses Cloudinary, using Django 1.8.
I downloaded the sample project from https://github.com/cloudinary/cloudinary-django-sample.
This line:
image = CloudinaryField('image')
causes an error when runnig "manage.py migrate" saying
django.db.utils.OperationalError: near "None": syntax error
Tried adding "null=True" and "blank=True" to the field definition
image = CloudinaryField('image', null=True, blank=True)
but I am getting the same result.
I import cloudinafield like this
from cloudinary.models import CloudinaryField
When I comment out the line with CloudinadyField there are no errors.
What can be the reason of this error?
Well, there is no such field type like the one you used.
For handling image you can either use CharField to store the url or use FileField to store the file key which will link the url.
You can find detailed configuration on this page.
I feel like an idiot, just updated cloudinary library to 1.1.3 and everything works fine now. Thanks Tal Lev-Ami
I've followed the tutorial and the examples for django-facebook from https://github.com/tschellenbach/Django-facebook/tree/master/facebook_example
I've got it up and running (as in i've run syncdb and migrations, and integrated the javascript and css code into my template).
When I click the link in my template, it successfully connects to Facebook and I can authorize. However, when it redirects, I get an error:
Request Method: POST
Request URL: http://127.0.0.1:8000/facebook/connect/?facebook_login=1
Django Version: 1.5.1
Exception Type: AttributeError
Exception Value: user or profile didnt have attribute facebook_id
Exception Location: /usr/local/lib/python2.7/dist-packages/django_facebook/utils.py in get_user_attribute, line 109
Python Executable: /usr/bin/python
Python Version: 2.7.3
This is within django-facebook's code, and I'm not sure if I've done something wrong with my setup. I've created my own UserProfile model which extends the abstract FacebookProfileModel class (I've tried using FacebookModel as well):
from django_facebook.models import FacebookProfileModel
from django.db.models.signals import post_save
class UserProfile(FacebookProfileModel):
user = models.OneToOneField('auth.User')
def create_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
post_save.connect(create_profile, sender=User)
I can see the profile get created in the db, although it's all nulls (except for the user id used in the foreign key). Not sure what I'm doing wrong, any pointers?
I found out what was wrong, and want to post the solution back. The problem was that I didn't specify AUTH_PROFILE_MODULE in my settings.py. In the django-facebook documentation, it didn't mention that when it gave the option to extend the profile class, so I missed it. Silly mistake!