django - KeyError: ('profiles', 'talk') - How do I resolve? -


newbie here. trying build app using django , postgres db. struggling migrate @ moment getting error "keyerror: ('profiles', 'talk')"

here error command line after trying migrate:

(myvenv) abbys-imac:talks abbyhumphreys$ python manage.py migrate /users/abbyhumphreys/talks/myvenv/lib/python3.4/site-packages/django/contrib/sites/models.py:78: removedindjango19warning: model class django.contrib.sites.models.site doesn't declare explicit app_label , either isn't in application in installed_apps or else imported before application loaded. no longer supported in django 1.9. class site(models.model):  system check identified issues:  warnings: profiles.profile.user: (fields.w342) setting unique=true on foreignkey has same effect using onetoonefield. hint: foreignkey(unique=true) better served onetoonefield. registration.registrationprofile.user: (fields.w342) setting unique=true on   foreignkey has same effect using onetoonefield. hint: foreignkey(unique=true) better served onetoonefield. operations perform: synchronize unmigrated apps: staticfiles, registration, humanize, messages apply migrations: profiles, auth, sessions, admin, contenttypes synchronizing apps without migrations: creating tables...     running deferred sql...     installing custom sql... running migrations:     rendering model states...traceback (most recent call last):     file "manage.py", line 10, in <module> execute_from_command_line(sys.argv)     file "/users/abbyhumphreys/talks/myvenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line utility.execute()     file "/users/abbyhumphreys/talks/myvenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 330, in execute self.fetch_command(subcommand).run_from_argv(self.argv)     file "/users/abbyhumphreys/talks/myvenv/lib/python3.4/site-packages/django/core/management/base.py", line 390, in run_from_argv self.execute(*args, **cmd_options)     file "/users/abbyhumphreys/talks/myvenv/lib/python3.4/site-packages/django/core/management/base.py", line 441, in execute output = self.handle(*args, **options)     file "/users/abbyhumphreys/talks/myvenv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 221, in handle executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)     file "/users/abbyhumphreys/talks/myvenv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 104, in migrate state = migration.mutate_state(state, preserve=do_run)     file "/users/abbyhumphreys/talks/myvenv/lib/python3.4/site-packages/django/db/migrations/migration.py", line 83, in mutate_state operation.state_forwards(self.app_label, new_state)     file "/users/abbyhumphreys/talks/myvenv/lib/python3.4/site-packages/django/db/migrations/operations/fields.py", line 256, in state_forwards n, f in state.models[app_label, self.model_name_lower].fields keyerror: ('profiles', 'talk') 

here models.py:

from django.contrib.auth.models import user django.db import models  class profile(models.model):     name = models.charfield(max_length=255)     sname = models.charfield(max_length=255, blank=true, null=true)     phone = models.charfield(max_length=255, blank=true, null=true)     mobile = models.charfield(max_length=255, blank=true, null=true)     email = models.emailfield(max_length=254, blank=true, null=true)     address = models.textfield(blank=true, null=true)     notes = models.textfield()     slug = models.slugfield(unique=true)     user = models.foreignkey(user, unique=true, blank=true, null=true, related_name="users")  class talk(models.model):     talk_no = models.charfield(max_length=255, blank=true, null=true)     talk_name = models.charfield(max_length=255, blank=true, null=true)     slug = models.slugfield(unique=true)  class congregation(models.model):     cong_name = models.charfield(max_length=255, blank=true, null=true)     meeting_time = models.charfield(max_length=255, blank=true, null=true)     cong_address = models.textfield(blank=true, null=true)     cong_phone = models.charfield(max_length=255, blank=true, null=true)     slug = models.slugfield(unique=true) 

here views.py:

from django.contrib.auth.decorators import login_required django.http import http404 django.shortcuts import render, render_to_response, redirect django.template import requestcontext profiles.forms import profileform, talkform, congform profiles.models import profile, talk, congregation django.template.defaultfilters import slugify  def index(request):     ids = profile.objects.all()     return render(request, 'index.html',{'ids': ids,})  def about(request):      return render(request, 'about.html',)  def contact(request):      return render(request, 'contact.html',)  def profile_detail(request, slug):     #grab object...     profile=profile.objects.get(slug=slug)     #and pass template     return render(request,'ids/profile_detail.html', {         'profile': profile,     })  @login_required def edit_profile(request, slug):     profile = profile.objects.get(slug=slug)     if profile.user != request.user:         raise http404      form_class = profileform      if request.method == 'post':         form = form_class(data=request.post, instance=profile)         if form.is_valid():             form.save()             return redirect('profile_detail', slug=profile.slug)     else:         form = form_class(instance=profile)     return render(request, 'ids/edit_profile.html', {'profile': profile, 'form': form, })  def create_profile(request):     form_class = profileform      if request.method == 'post':         form=form_class(request.post)         if form.is_valid():             profile=form.save(commit=false)             profile.user = request.user             profile.slug = slugify(profile.name)             profile.save()             slug = slugify(name)         return redirect('profile_detail', slug=profile.slug)     else:         form=form_class()     return render(request, 'ids/create_profile.html', {'form': form,})  def browse_by_name(request, initial=none):     if initial:         ids = profile.objects.filter(name__istartswith=initial).order_by('name')     else:         ids = profile.objects.all().order_by('name')      return render_to_response('search/search.html', {'ids': ids, 'initial': initial,}, context_instance=requestcontext(request))  def talk_detail(request, slug):     #grab object...     talk=talk.objects.get(slug=slug)     #and pass template     return render(request,'ids/talk_detail.html', {         'talk': talk,     })  @login_required def edit_talk(request, slug):     talk = talk.objects.get(slug=slug)     if profile.user != request.user:         raise http404      form_class = talkform      if request.method == 'post':         form = form_class(data=request.post, instance=talk)         if form.is_valid():             form.save()             return redirect('talk_detail', slug=slug.slug)     else:         form = form_class(instance=talk)     return render(request, 'ids/edit_talk.html', {'talk': talk, 'form': form,   })  def create_talk(request):     form_class = talkform      if request.method == 'post':         form=form_class(request.post)         if form.is_valid():             talk=form.save(commit=false)             profile.user = request.user             talk.slug = slugify(talk.talk_no)             talk.save()             slug = slugify(talk_no)         return redirect('talk_detail', slug=talk.slug)     else:         form=form_class()     return render(request, 'ids/create_talk.html', {'form': form,})  def cong_detail(request, slug):     #grab object...     cong=congregation.objects.get(slug=slug)     #and pass template     return render(request,'ids/cong_detail.html', {         'cong': cong,     })  @login_required def edit_cong(request, slug):     cong = congregation.objects.get(slug=slug)     if profile.user != request.user:         raise http404      form_class = congform      if request.method == 'post':         form = form_class(data=request.post, instance=cong)         if form.is_valid():             form.save()             return redirect('cong_detail', slug=cong.slug)     else:         form = form_class(instance=cong)     return render(request, 'ids/edit_cong.html', {'cong': cong, 'form': form, })  def create_cong(request):     form_class = congform      if request.method == 'post':         form=form_class(request.post)         if form.is_valid():             cong=form.save(commit=false)             profile.user = request.user             cong.slug = slugify(cong.cong_name)             cong.save()             slug = slugify(cong_name)         return redirect('cong_detail', slug=cong.slug)     else:         form=form_class()     return render(request, 'ids/create_cong.html', {'form': form,}) 

here url.py

from django.contrib import admin profiles.backends import myregistrationview django.conf.urls import patterns, include, url django.contrib import admin django.views.generic import templateview, redirectview django.contrib.auth.views import password_reset, password_reset_done,  password_reset_confirm, password_reset_complete  urlpatterns = patterns('',     url(r'^$', 'profiles.views.index', name='home'),     url(r'^about/$', templateview.as_view(template_name='about.html'), name='about'),     url(r'^contact/$', templateview.as_view(template_name='contact.html'), name='contact'),      url(r'^ids/$', redirectview.as_view(pattern_name='browse')),     url(r'^ids/(?p<slug>[-\w]+)/$', 'profiles.views.profile_detail', name='profile_detail'),     url(r'^ids/(?p<slug>[-\w]+)/edit/$', 'profiles.views.edit_profile', name='edit_profile'),      url(r'^ids/(?p<slug>[-\w]+)/$', 'profiles.views.talk_detail', name='talk_detail'),     url(r'^ids/(?p<slug>[-\w]+)/edit/$', 'profiles.views.edit_talk', name='edit_talk'),      url(r'^ids/(?p<slug>[-\w]+)/$', 'profiles.views.cong_detail', name='cong_detail'),     url(r'^ids/(?p<slug>[-\w]+)/edit/$', 'profiles.views.edit_cong', name='edit_cong'),      url(r'^browse/$', redirectview.as_view(pattern_name='browse')),     url(r'^browse/name/$','profiles.views.browse_by_name', name='browse'),     url(r'^browse/name/(?p<initial>[-\w]+)/$', 'profiles.views.browse_by_name', name='browse_by_name'),      url(r'^accounts/password/reset/$', password_reset,      {'template_name': 'registration/password_reset_form.html'},      name="password_reset"),     url(r'^accounts/password/reset/done/$',      password_reset_done,      {'template_name': 'registration/password_reset_done.html'},      name="password_reset_done"),     url(r'^accounts/password/reset/(?p<uidb64>[0-9a-za-z_\-]+)/(?p<token>[0-9a-za-z]{1,13}-[0-9a-za-z]{1,20})/$',     password_reset_confirm,      {'template_name': 'registration/password_reset_confirm.html'},      name="password_reset_confirm"),     url(r'^accounts/password/done/$', password_reset_complete,     {'template_name': 'registration/password_reset_complete.html'},     name="password_reset_complete"),      url(r'^accounts/register/$', myregistrationview.as_view(), name='registration_register'),     url(r'^accounts/create_profile/$', 'profiles.views.create_profile', name='registration_create_profile'),     url(r'^accounts/create_talk/$', 'profiles.views.create_talk', name='registration_create_talk'),     url(r'^accounts/create_cong/$', 'profiles.views.create_cong', name='registration_create_cong'),      url(r'^accounts/', include('registration.backends.default.urls')),     url(r'^admin/', include(admin.site.urls)), ) 

not sure if i've given or little info, being newbie, have no idea error means or information might need figure out!

thank in advance in resolving problem , patience in looking @ awful code! :-s

this happens when following steps:

  1. run

migrate appname

and execution stopped because of error.

  1. you run again, time error because new table created.

  2. you edit migration file, remove code part creating table, run migration again.

my workaround is, instead of removing createmodel, moved previous migration file.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -