Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
115 views
in Technique[技术] by (71.8m points)

python - Django - no such table exception

In Django, I've added some models into models.py. After manage.py makemigrations, manage.py migrate raised this exception:

django.db.utils.OperationalError: no such table: auth_test_usertranslatorprofile

So I've removed all old migrations and run makemigrations and migrate again which seemed to work.

Unfortunately, I've noticed that it didn't helped because when I try to click on User customer profiles of User translator profiles it raises exception:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/admin/auth_test/usertranslatorprofile/

Django Version: 1.8.7
Python Version: 2.7.10
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'auth_test')
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 "C:Python27libsite-packagesdjangocorehandlersase.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:Python27libsite-packagesdjangocontribadminoptions.py" in wrapper
  618.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:Python27libsite-packagesdjangoutilsdecorators.py" in _wrapped_view
  110.                     response = view_func(request, *args, **kwargs)
File "C:Python27libsite-packagesdjangoviewsdecoratorscache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)
File "C:Python27libsite-packagesdjangocontribadminsites.py" in inner
  233.             return view(request, *args, **kwargs)
File "C:Python27libsite-packagesdjangoutilsdecorators.py" in _wrapper
  34.             return bound_func(*args, **kwargs)
File "C:Python27libsite-packagesdjangoutilsdecorators.py" in _wrapped_view
  110.                     response = view_func(request, *args, **kwargs)
File "C:Python27libsite-packagesdjangoutilsdecorators.py" in bound_func
  30.                 return func.__get__(self, type(self))(*args2, **kwargs2)
File "C:Python27libsite-packagesdjangocontribadminoptions.py" in changelist_view
  1550.                 self.list_max_show_all, self.list_editable, self)
File "C:Python27libsite-packagesdjangocontribadminviewsmain.py" in __init__
  82.         self.get_results(request)
File "C:Python27libsite-packagesdjangocontribadminviewsmain.py" in get_results
  177.         result_count = paginator.count
File "C:Python27libsite-packagesdjangocorepaginator.py" in _get_count
  72.                 self._count = self.object_list.count()
File "C:Python27libsite-packagesdjangodbmodelsquery.py" in count
  318.         return self.query.get_count(using=self.db)
File "C:Python27libsite-packagesdjangodbmodelssqlquery.py" in get_count
  466.         number = obj.get_aggregation(using, ['__count'])['__count']
File "C:Python27libsite-packagesdjangodbmodelssqlquery.py" in get_aggregation
  447.         result = compiler.execute_sql(SINGLE)
File "C:Python27libsite-packagesdjangodbmodelssqlcompiler.py" in execute_sql
  840.             cursor.execute(sql, params)
File "C:Python27libsite-packagesdjangodbackendsutils.py" in execute
  79.             return super(CursorDebugWrapper, self).execute(sql, params)
File "C:Python27libsite-packagesdjangodbackendsutils.py" in execute
  64.                 return self.cursor.execute(sql, params)
File "C:Python27libsite-packagesdjangodbutils.py" in __exit__
  98.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:Python27libsite-packagesdjangodbackendsutils.py" in execute
  64.                 return self.cursor.execute(sql, params)
File "C:Python27libsite-packagesdjangodbackendssqlite3ase.py" in execute
  318.         return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /admin/auth_test/usertranslatorprofile/
Exception Value: no such table: auth_test_usertranslatorprofile

I'm attaching my files:

MODELS.PY:

from django.db import models
from django.contrib.auth.models import User

class Language(models.Model):
    shortcut = models.CharField(max_length=6)
    name = models.CharField(max_length=50)
    price_per_sign = models.FloatField()

class UserTranslatorProfile(models.Model):
    user = models.OneToOneField(User)
    languages = models.ManyToManyField(Language)
    price_per_word = models.FloatField()

class UserCustomerProfile(models.Model):
    user = models.OneToOneField(User)

ADMIN.PY:

from django import forms
from .models import Language
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
class FreelancerRegistrationForm(forms.Form):
    language = forms.ModelChoiceField(queryset=Language.objects.all().order_by('shortcut'))

Do you know where is the problem? Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I solved the same problem with these steps :

  • Delete your database (db.sqlite3 in my case) in your project directory
  • Remove everything from __pycache__ folder under your project subdirectory
  • For the application you are trying to fix, go to the folder and clear migrations and __pycache__ directories

When you are sure you have cleared all the above files, run:

python manage.py makemigrations
python manage.py migrate

I hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...