In Django I added models into models.py
. After manage.py makemigrations
, manage.py migrate
raised this exception:
django.db.utils.OperationalError: no such table: auth_test_usertranslatorprofile
I removed all old migrations and run makemigrations
and migrate
again which seemed to work. It didn’t help because when I click User customer profiles
of User translator profiles
it raises exception:
JavaScript
x
71
71
1
Request Method: GET
2
Request URL: http://127.0.0.1:8000/admin/auth_test/usertranslatorprofile/
3
4
Django Version: 1.8.7
5
Python Version: 2.7.10
6
Installed Applications:
7
('django.contrib.admin',
8
'django.contrib.auth',
9
'django.contrib.contenttypes',
10
'django.contrib.sessions',
11
'django.contrib.messages',
12
'django.contrib.staticfiles',
13
'auth_test')
14
Installed Middleware:
15
('django.contrib.sessions.middleware.SessionMiddleware',
16
'django.middleware.common.CommonMiddleware',
17
'django.middleware.csrf.CsrfViewMiddleware',
18
'django.contrib.auth.middleware.AuthenticationMiddleware',
19
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
20
'django.contrib.messages.middleware.MessageMiddleware',
21
'django.middleware.clickjacking.XFrameOptionsMiddleware',
22
'django.middleware.security.SecurityMiddleware')
23
24
25
Traceback:
26
File "C:Python27libsite-packagesdjangocorehandlersbase.py" in get_response
27
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
28
File "C:Python27libsite-packagesdjangocontribadminoptions.py" in wrapper
29
618. return self.admin_site.admin_view(view)(*args, **kwargs)
30
File "C:Python27libsite-packagesdjangoutilsdecorators.py" in _wrapped_view
31
110. response = view_func(request, *args, **kwargs)
32
File "C:Python27libsite-packagesdjangoviewsdecoratorscache.py" in _wrapped_view_func
33
57. response = view_func(request, *args, **kwargs)
34
File "C:Python27libsite-packagesdjangocontribadminsites.py" in inner
35
233. return view(request, *args, **kwargs)
36
File "C:Python27libsite-packagesdjangoutilsdecorators.py" in _wrapper
37
34. return bound_func(*args, **kwargs)
38
File "C:Python27libsite-packagesdjangoutilsdecorators.py" in _wrapped_view
39
110. response = view_func(request, *args, **kwargs)
40
File "C:Python27libsite-packagesdjangoutilsdecorators.py" in bound_func
41
30. return func.__get__(self, type(self))(*args2, **kwargs2)
42
File "C:Python27libsite-packagesdjangocontribadminoptions.py" in changelist_view
43
1550. self.list_max_show_all, self.list_editable, self)
44
File "C:Python27libsite-packagesdjangocontribadminviewsmain.py" in __init__
45
82. self.get_results(request)
46
File "C:Python27libsite-packagesdjangocontribadminviewsmain.py" in get_results
47
177. result_count = paginator.count
48
File "C:Python27libsite-packagesdjangocorepaginator.py" in _get_count
49
72. self._count = self.object_list.count()
50
File "C:Python27libsite-packagesdjangodbmodelsquery.py" in count
51
318. return self.query.get_count(using=self.db)
52
File "C:Python27libsite-packagesdjangodbmodelssqlquery.py" in get_count
53
466. number = obj.get_aggregation(using, ['__count'])['__count']
54
File "C:Python27libsite-packagesdjangodbmodelssqlquery.py" in get_aggregation
55
447. result = compiler.execute_sql(SINGLE)
56
File "C:Python27libsite-packagesdjangodbmodelssqlcompiler.py" in execute_sql
57
840. cursor.execute(sql, params)
58
File "C:Python27libsite-packagesdjangodbbackendsutils.py" in execute
59
79. return super(CursorDebugWrapper, self).execute(sql, params)
60
File "C:Python27libsite-packagesdjangodbbackendsutils.py" in execute
61
64. return self.cursor.execute(sql, params)
62
File "C:Python27libsite-packagesdjangodbutils.py" in __exit__
63
98. six.reraise(dj_exc_type, dj_exc_value, traceback)
64
File "C:Python27libsite-packagesdjangodbbackendsutils.py" in execute
65
64. return self.cursor.execute(sql, params)
66
File "C:Python27libsite-packagesdjangodbbackendssqlite3base.py" in execute
67
318. return Database.Cursor.execute(self, query, params)
68
69
Exception Type: OperationalError at /admin/auth_test/usertranslatorprofile/
70
Exception Value: no such table: auth_test_usertranslatorprofile
71
models.py:
JavaScript
1
16
16
1
from django.db import models
2
from django.contrib.auth.models import User
3
4
class Language(models.Model):
5
shortcut = models.CharField(max_length=6)
6
name = models.CharField(max_length=50)
7
price_per_sign = models.FloatField()
8
9
class UserTranslatorProfile(models.Model):
10
user = models.OneToOneField(User)
11
languages = models.ManyToManyField(Language)
12
price_per_word = models.FloatField()
13
14
class UserCustomerProfile(models.Model):
15
user = models.OneToOneField(User)
16
admin.py:
JavaScript
1
7
1
from django import forms
2
from .models import Language
3
from django.contrib.auth.models import User
4
from django.contrib.auth.forms import UserCreationForm
5
class FreelancerRegistrationForm(forms.Form):
6
language = forms.ModelChoiceField(queryset=Language.objects.all().order_by('shortcut'))
7
What is the problem?
Advertisement
Answer
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:
JavaScript
1
3
1
python manage.py makemigrations
2
python manage.py migrate
3