python - ProgrammingError 'column "scheme_id" of relation "value_calculator_newunit" does not exist' in Django 1.8.3 -


after lot of googling haven't been able find resolves specific issue. person's problem appears similar mine, it's not migration issue, python3 manage.py makemigrations followed python3 manage.py migrate doesn't resolve problem (no error messages), nor did resetting database empty state python3 manage.py flush.

the error occurs whenever create scheme without associated newunit or refurbunit , try view or delete in admin interface (consequently becomes undeleteable in shell), or when try create new 1 refurbunit or newunit, in case doesn't created @ all.

the project i'm working on far not different completed tutorial; substantial difference in views.py each project's main app. i'll post error message , code both project's app , tutorial's polls app (just reference, can't find up-to-date pre-completed tutorial project can compare code against):

error message

environment:   request method: post request url: http://127.0.0.1:8000/admin/value_calculator/scheme/add/  django version: 1.8.3 python version: 3.4.0 installed applications: ('django.contrib.admin',  'django.contrib.auth',  'django.contrib.contenttypes',  'django.contrib.sessions',  'django.contrib.messages',  'django.contrib.staticfiles',  'value_calculator') installed middleware: ('django.contrib.sessions.middleware.sessionmiddleware',  'django.middleware.common.commonmiddleware',  'django.middleware.csrf.csrfviewmiddleware',  'django.contrib.auth.middleware.authenticationmiddleware',  'django.contrib.auth.middleware.sessionauthenticationmiddleware',  'django.contrib.messages.middleware.messagemiddleware',  'django.middleware.clickjacking.xframeoptionsmiddleware',  'django.middleware.security.securitymiddleware')   traceback: file "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py" in get_response   132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs) file "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/options.py" in wrapper   616.                 return self.admin_site.admin_view(view)(*args, **kwargs) file "/usr/local/lib/python3.4/dist-packages/django/utils/decorators.py" in _wrapped_view   110.                     response = view_func(request, *args, **kwargs) file "/usr/local/lib/python3.4/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func   57.         response = view_func(request, *args, **kwargs) file "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/sites.py" in inner   233.             return view(request, *args, **kwargs) file "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/options.py" in add_view   1516.         return self.changeform_view(request, none, form_url, extra_context) file "/usr/local/lib/python3.4/dist-packages/django/utils/decorators.py" in _wrapper   34.             return bound_func(*args, **kwargs) file "/usr/local/lib/python3.4/dist-packages/django/utils/decorators.py" in _wrapped_view   110.                     response = view_func(request, *args, **kwargs) file "/usr/local/lib/python3.4/dist-packages/django/utils/decorators.py" in bound_func   30.                 return func.__get__(self, type(self))(*args2, **kwargs2) file "/usr/lib/python3.4/contextlib.py" in inner   30.                 return func(*args, **kwds) file "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/options.py" in changeform_view   1468.                 self.save_related(request, form, formsets, not add) file "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/options.py" in save_related   1102.             self.save_formset(request, form, formset, change=change) file "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/options.py" in save_formset   1090.         formset.save() file "/usr/local/lib/python3.4/dist-packages/django/forms/models.py" in save   640.         return self.save_existing_objects(commit) + self.save_new_objects(commit) file "/usr/local/lib/python3.4/dist-packages/django/forms/models.py" in save_new_objects   771.             self.new_objects.append(self.save_new(form, commit=commit)) file "/usr/local/lib/python3.4/dist-packages/django/forms/models.py" in save_new   904.             obj.save() file "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py" in save   710.                        force_update=force_update, update_fields=update_fields) file "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py" in save_base   738.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) file "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py" in _save_table   822.             result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) file "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py" in _do_insert   861.                                using=using, raw=raw) file "/usr/local/lib/python3.4/dist-packages/django/db/models/manager.py" in manager_method   127.                 return getattr(self.get_queryset(), name)(*args, **kwargs) file "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py" in _insert   920.         return query.get_compiler(using=using).execute_sql(return_id) file "/usr/local/lib/python3.4/dist-packages/django/db/models/sql/compiler.py" in execute_sql   974.                 cursor.execute(sql, params) file "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py" in execute   79.             return super(cursordebugwrapper, self).execute(sql, params) file "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py" in execute   64.                 return self.cursor.execute(sql, params) file "/usr/local/lib/python3.4/dist-packages/django/db/utils.py" in __exit__   97.                 six.reraise(dj_exc_type, dj_exc_value, traceback) file "/usr/local/lib/python3.4/dist-packages/django/utils/six.py" in reraise   658.             raise value.with_traceback(tb) file "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py" in execute   64.                 return self.cursor.execute(sql, params)  exception type: programmingerror @ /admin/value_calculator/scheme/add/ exception value: column "scheme_id" of relation "value_calculator_newunit" not exist line 1: insert "value_calculator_newunit" ("scheme_id", "d", "f...                                                 ^ 

my app's code

admin.py

from django.contrib import admin .models import scheme, newunit, refurbunit  class newunitinline(admin.tabularinline):     model = newunit     = 0  class refurbunitinline(admin.tabularinline):     model = refurbunit     = 0  class schemeadmin(admin.modeladmin):     #fieldsets = [     #    (none,               {'fields': ['name']}),     #    ('date information', {'fields': ['date']}),     #]     inlines = [newunitinline, refurbunitinline]     list_display = ("name", "date")     list_filter = ["date"]  admin.site.register(scheme, schemeadmin) 

models.py

from django.db import models  class scheme(models.model):     #scheme_id = models.integerfield(unique=true, primary_key=true) #makes absolutely no difference.     name = models.charfield(max_length=200)     new_units = models.integerfield(default=0)     refurb_units = models.integerfield(default=0)     date = models.datetimefield()     appraiser = models.charfield(max_length=200, default="nobody", blank=true)      #fixme: method broken due foreignkeys in newunit , refurbunit     def get_fields(self):         return [(field.name, field.value_to_string(self)) field in self._meta.get_fields()]      def __str__(self):         return self.name  class newunit(models.model):     scheme = models.foreignkey(scheme)     d = models.charfield(max_length=200)     floor_area = models.integerfield(default=0)     units = models.integerfield(default=0)     build_price_per_m2 = models.floatfield(default=0)     build_price_per_unit = models.floatfield(default=0)     affordable_ratio = models.floatfield(default=0) #actually percentage field rather ratio  class refurbunit(models.model):     scheme = models.foreignkey(scheme)     resale_price = models.floatfield()      selling_costs = models.floatfield() #this percentage, , paired below field absolute figure     legal_costs = models.floatfield()     refurbishment_costs = models.floatfield()     other_costs = models.floatfield() 

urls.py

from django.conf.urls import url . import views  urlpatterns = [     url(r'^$', views.index, name='index'),     url(r'^(?p<scheme_id>[0-9]+)/$', views.detail, name='detail'), ] 

views.py

from django.shortcuts import render, get_object_or_404 django.http import httpresponse, http404  .models import scheme, newunit, refurbunit   def index(request):     scheme_list = scheme.objects.order_by("-date")[:5]     context = {"scheme_list": scheme_list}     return render(request, "value_calculator/index.html", context)  def detail(request, scheme_id):     scheme = get_object_or_404(scheme, pk=scheme_id)     return render(request, "value_calculator/detail.html", {"scheme": scheme}) 

tests.py

import datetime  django.test import testcase django.core.urlresolvers import reverse django.utils import timezone  .models import scheme, newunit, refurbunit  def create_scheme(name, days=0, new_units=0, refurb_units=0, appraiser=""):     """days offset value current date"""     time = timezone.now() + datetime.timedelta(days=days)     return scheme.objects.create(name=name, date=time, new_units=new_units, refurb_units=refurb_units, appraiser=appraiser)  class schememethodtests(testcase):     def test_get_fields(self):         """test types , lengths correct."""         scheme = create_scheme("test")         data = scheme.get_fields()         print(data)         self.assertequal(len(data), 6)         self.assertequal(type(data), list)          item in data:             self.assertequal(type(item), tuple)  class schemeviewtests(testcase):     def test_index_view_with_no_schemes(self):         response = self.client.get(reverse('value_calculator:index'))         self.assertequal(response.status_code, 200)         self.assertcontains(response, "no schemes available. please add via admin page.")         self.assertquerysetequal(response.context['scheme_list'], [])      def test_index_view_with_past_date(self):         create_scheme("past scheme", days=-30)         response = self.client.get(reverse('value_calculator:index'))         self.assertquerysetequal(             response.context["scheme_list"],             ["<scheme: past scheme>"]         )      def test_index_view_with_future_date(self):         create_scheme("future scheme", days=30)         response = self.client.get(reverse('value_calculator:index'))         self.assertquerysetequal(             response.context["scheme_list"],             ["<scheme: future scheme>"]         ) 

tutorial's polls app code

admin.py

from django.contrib import admin .models import choice, question  class choiceinline(admin.tabularinline):     model = choice     = 3  class questionadmin(admin.modeladmin):     fieldsets = [         (none,               {'fields': ['question_text']}),         ('date information', {'fields': ['pub_date']}),     ]     inlines = [choiceinline]     list_display = ('question_text', 'pub_date', 'was_published_recently')     list_filter = ['pub_date']     search_fields = ['question_text']  admin.site.register(question, questionadmin) 

models.py

import datetime django.utils import timezone django.db import models  # create models here. class question(models.model):     def __str__(self):         return self.question_text     def was_published_recently(self):         = timezone.now()         return - datetime.timedelta(days=1) <= self.pub_date <=       was_published_recently.admin_order_field = 'pub_date'     was_published_recently.boolean = true     was_published_recently.short_description = 'published recently?'      question_text = models.charfield(max_length=200)     pub_date = models.datetimefield('date published')  class choice(models.model):     def __str__(self):         return self.choice_text     question = models.foreignkey(question)     choice_text = models.charfield(max_length=200)     votes = models.integerfield(default=0) 

urls.py

from django.conf.urls import url . import views  urlpatterns = [     # ex: /polls     url(r'^$', views.index, name='index'),     # ex: /polls/5     url(r'^(?p<question_id>[0-9]+)/$', views.detail, name='detail'),     # ex: /polls/5/results/     url(r'^(?p<question_id>[0-9]+)/results/$', views.results, name='results'),     # ex: /polls/5/vote/     url(r'^(?p<question_id>[0-9]+)/vote/$', views.vote, name='vote'), ] 

views.py

from django.shortcuts import render, get_object_or_404 django.http import httpresponse, http404, httpresponseredirect django.core.urlresolvers import reverse django.template import requestcontext, loader django.utils import timezone django.views import generic  .models import choice, question  class indexview(generic.listview):     template_name = 'polls/index.html'     context_object_name = 'latest_question_list'      def get_queryset(self):         """return last 5 published questions."""         return question.objects.filter(         pub_date__lte=timezone.now()     ).order_by('-pub_date')[:5]    class detailview(generic.detailview):     model = question     template_name = 'polls/detail.html'      def get_queryset(self):         """         excludes questions aren't published yet.         """         return question.objects.filter(pub_date__lte=timezone.now())   class resultsview(generic.detailview):     model = question     template_name = 'polls/results.html'  def index(request):     latest_question_list = question.objects.order_by('-pub_date')[:5]     context = {'latest_question_list': latest_question_list}     return render(request, 'polls/index.html', context)  def detail(request, question_id):     question = get_object_or_404(question, pk=question_id)     return render(request, 'polls/detail.html', {'question': question})  def results(request, question_id):     response = "you're looking @ results of question %s."     return httpresponse(response % question_id)  def vote(request, question_id):     p = get_object_or_404(question, pk=question_id)     try:         selected_choice = p.choice_set.get(pk=request.post['choice'])     except (keyerror, choice.doesnotexist):         # redisplay question voting form.         return render(request, 'polls/detail.html', {             'question': p,             'error_message': "you didn't select choice.",         })     else:         selected_choice.votes += 1         selected_choice.save()         # return httpresponseredirect after dealing         # post data. prevents data being posted twice if         # user hits button.         return httpresponseredirect(reverse('polls:results', args=(p.id,))) 

tests.py

import datetime  django.utils import timezone django.test import testcase django.core.urlresolvers import reverse  .models import question  def create_question(question_text, days):     """     creates question given `question_text` published given     number of `days` offset (negative questions published     in past, positive questions have yet published).     """     time = timezone.now() + datetime.timedelta(days=days)     return question.objects.create(question_text=question_text,                                    pub_date=time)   class questionviewtests(testcase):     def test_index_view_with_no_questions(self):         """         if no questions exist, appropriate message should displayed.         """         response = self.client.get(reverse('polls:index'))         self.assertequal(response.status_code, 200)         self.assertcontains(response, "no polls available.")         self.assertquerysetequal(response.context['latest_question_list'], [])      def test_index_view_with_a_past_question(self):         """         questions pub_date in past should displayed on         index page.         """         create_question(question_text="past question.", days=-30)         response = self.client.get(reverse('polls:index'))         self.assertquerysetequal(             response.context['latest_question_list'],             ['<question: past question.>']         )      def test_index_view_with_a_future_question(self):         """         questions pub_date in future should not displayed on         index page.         """         create_question(question_text="future question.", days=30)         response = self.client.get(reverse('polls:index'))         self.assertcontains(response, "no polls available.",                             status_code=200)         self.assertquerysetequal(response.context['latest_question_list'], [])      def test_index_view_with_future_question_and_past_question(self):         """         if both past , future questions exist, past questions         should displayed.         """         create_question(question_text="past question.", days=-30)         create_question(question_text="future question.", days=30)         response = self.client.get(reverse('polls:index'))         self.assertquerysetequal(             response.context['latest_question_list'],             ['<question: past question.>']         )      def test_index_view_with_two_past_questions(self):         """         questions index page may display multiple questions.         """         create_question(question_text="past question 1.", days=-30)         create_question(question_text="past question 2.", days=-5)         response = self.client.get(reverse('polls:index'))         self.assertquerysetequal(             response.context['latest_question_list'],             ['<question: past question 2.>', '<question: past question 1.>']         )   class questionmethodtests(testcase):     def test_was_published_recently_with_future_question(self):         """         was_published_recently() should return false questions         pub_date in future.         """         time = timezone.now() + datetime.timedelta(days=30)         future_question = question(pub_date=time)         self.assertequal(future_question.was_published_recently(), false)      def test_was_published_recently_with_old_question(self):         """         was_published_recently() should return false questions         pub_date older 1 day.         """         time = timezone.now() - datetime.timedelta(days=30)         old_question = question(pub_date=time)         self.assertequal(old_question.was_published_recently(), false)      def test_was_published_recently_with_recent_question(self):         """         was_published_recently() should return true questions         pub_date within last day.         """         time = timezone.now() - datetime.timedelta(hours=1)         recent_question = question(pub_date=time)         self.assertequal(recent_question.was_published_recently(), true)  class questionindexdetailtests(testcase):     def test_detail_view_with_a_future_question(self):         """         detail view of question pub_date in future should         return 404 not found.         """         future_question = create_question(question_text='future question.',                                           days=5)         response = self.client.get(reverse('polls:detail',                                    args=(future_question.id,)))         self.assertequal(response.status_code, 404)      def test_detail_view_with_a_past_question(self):         """         detail view of question pub_date in past should         display question's text.         """         past_question = create_question(question_text='past question.',                                         days=-5)         response = self.client.get(reverse('polls:detail',                                    args=(past_question.id,)))         self.assertcontains(response, past_question.question_text,                             status_code=200) 

also, i'm running linux mint 17.2 , postgresql 9.3.9.

i found problem database in postgresql, although unfortunately don't know went wrong. dropped , re-created dropdb , createdb, ran manage.py migrate; assumption manage.py flush clear absolutely faulty.

thanks daniel roseman leading me solution pointing out migration issue.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -