# error - no such table

**URL:** <https://forum.djangoproject.com/t/error-no-such-table/5632>\
**Category:** Using the ORM\
**Created:** [December 9, 2020, 7:49pm UTC](https://forum.djangoproject.com/t/error-no-such-table/5632 "2020-12-09T19:49:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![bouseman](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/bouseman/32/2771_2.png) [@bouseman](https://forum.djangoproject.com/u/bouseman)\
**Post date:** [December 9, 2020, 7:49pm UTC](https://forum.djangoproject.com/t/error-no-such-table/5632/1 "2020-12-09T19:49:15Z")

</div>

I’m trying to make an e-mail authorization and get an error when creating superuser. What’s wrong?

application ‘www’  
models.py

> from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin  
> from django.db import models  
> from django.utils import timezone
> 
> class UserManager(BaseUserManager):
> 
> def \_create\_user(self, email, password, is\_staff, is\_superuser, \*\*extra\_fields):  
> if not email:  
> raise ValueError(‘Users must have an email address’)  
> now = timezone.now()  
> email = self.normalize\_email(email)  
> user = self.model(  
> email=email,  
> is\_staff=is\_staff,  
> is\_active=True,  
> is\_superuser=is\_superuser,  
> last\_login=now,  
> date\_joined=now,  
> \*\*extra\_fields  
> )  
> user.set\_password(password)  
> user.save(using=self.\_db)  
> return user
> 
> def create\_user(self, email, password, \*\*extra\_fields):  
> return self.\_create\_user(email, password, False, False, \*\*extra\_fields)
> 
> def create\_superuser(self, email, password, \*\*extra\_fields):  
> user=self.\_create\_user(email, password, True, True, \*\*extra\_fields)  
> return user
> 
> class User(AbstractBaseUser, PermissionsMixin):  
> email = models.EmailField(max\_length=254, unique=True)  
> name = models.CharField(max\_length=254, null=True, blank=True)  
> is\_staff = models.BooleanField(default=False)  
> is\_superuser = models.BooleanField(default=False)  
> is\_active = models.BooleanField(default=True)  
> last\_login = models.DateTimeField(null=True, blank=True)  
> date\_joined = models.DateTimeField(auto\_now\_add=True)
> 
> ```
> USERNAME_FIELD = 'email'
> EMAIL_FIELD = 'email'
> REQUIRED_FIELDS = []
> 
> objects = UserManager()
> 
> def get_absolute_url(self):
> return "/users/%i/" % (self.pk)
> 
> ```

settings.py

> INSTALLED\_APPS = [  
> ‘django.contrib.admin’,  
> ‘django.contrib.auth’,  
> ‘django.contrib.contenttypes’,  
> ‘django.contrib.sessions’,  
> ‘django.contrib.messages’,  
> ‘django.contrib.staticfiles’,  
> ‘www’,  
> ]
> 
> ROOT\_URLCONF = ‘www.urls’
> 
> AUTH\_PASSWORD\_VALIDATORS = [  
> {  
> ‘NAME’: ‘django.contrib.auth.password\_validation.UserAttributeSimilarityValidator’,  
> },  
> {  
> ‘NAME’: ‘django.contrib.auth.password\_validation.MinimumLengthValidator’,  
> },  
> {  
> ‘NAME’: ‘django.contrib.auth.password\_validation.CommonPasswordValidator’,  
> },  
> {  
> ‘NAME’: ‘django.contrib.auth.password\_validation.NumericPasswordValidator’,  
> },  
> ]
> 
> AUTH\_USER\_MODEL = ‘www.User’

error

> (env) isaev@web:~/plg/www$ python manage.py createsuperuser  
> Email: [isaev@plg.ru](mailto:isaev@plg.ru)  
> Traceback (most recent call last):  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/utils.py”, line 84, in \_execute  
> return self.cursor.execute(sql, params)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py”, line 413, in execute  
> return Database.Cursor.execute(self, query, params)  
> sqlite3.OperationalError: no such table: www\_user
> 
> The above exception was the direct cause of the following exception:
> 
> Traceback (most recent call last):  
> File “manage.py”, line 22, in   
> main()  
> File “manage.py”, line 18, in main  
> execute\_from\_command\_line(sys.argv)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/core/management/ **init**.py”, line 401, in execute\_from\_command\_line  
> utility.execute()  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/core/management/ **init**.py”, line 395, in execute  
> self.fetch\_command(subcommand).run\_from\_argv(self.argv)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/core/management/base.py”, line 330, in run\_from\_argv  
> self.execute(\*args, \*\*cmd\_options)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py”, line 79, in execute  
> return super().execute(\*args, \*\*options)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/core/management/base.py”, line 371, in execute  
> output = self.handle(\*args, **options)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py”, line 113, in handle  
> error\_msg = self.\_validate\_username(username, verbose\_field\_name, database)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py”, line 234, in \_validate\_username  
> self.UserModel.\_default\_manager.db\_manager(database).get\_by\_natural\_key(username)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/contrib/auth/base\_user.py”, line 45, in get\_by\_natural\_key  
> return self.get(**{self.model.USERNAME\_FIELD: username})  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/models/manager.py”, line 85, in manager\_method  
> return getattr(self.get\_queryset(), name)(\*args, \*\*kwargs)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/models/query.py”, line 425, in get  
> num = len(clone)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/models/query.py”, line 269, in **len**  
> self.\_fetch\_all()  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/models/query.py”, line 1308, in \_fetch\_all  
> self.\_result\_cache = list(self.\_iterable\_class(self))  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/models/query.py”, line 53, in **iter**  
> results = compiler.execute\_sql(chunked\_fetch=self.chunked\_fetch, chunk\_size=self.chunk\_size)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/models/sql/compiler.py”, line 1156, in execute\_sql  
> cursor.execute(sql, params)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/utils.py”, line 98, in execute  
> return super().execute(sql, params)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/utils.py”, line 66, in execute  
> return self.\_execute\_with\_wrappers(sql, params, many=False, executor=self.\_execute)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/utils.py”, line 75, in \_execute\_with\_wrappers  
> return executor(sql, params, many, context)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/utils.py”, line 84, in \_execute  
> return self.cursor.execute(sql, params)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/utils.py”, line 90, in **exit**  
> raise dj\_exc\_value.with\_traceback(traceback) from exc\_value  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/utils.py”, line 84, in \_execute  
> return self.cursor.execute(sql, params)  
> File “/home/isaev/plg/env/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py”, line 413, in execute  
> return Database.Cursor.execute(self, query, params)  
> django.db.utils.OperationalError: no such table: www\_user

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 9, 2020, 7:52pm UTC](https://forum.djangoproject.com/t/error-no-such-table/5632/2 "2020-12-09T19:52:12Z")

</div>

Did you do a makemigrations followed by a migrate? Did you see the table being created as part of the migrate process? Can you go directly into the database and verify that the table exists?

---

<div class="post-metadata">

**Author:** ![bouseman](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/bouseman/32/2771_2.png) [@bouseman](https://forum.djangoproject.com/u/bouseman)\
**Post date:** [December 9, 2020, 8:00pm UTC](https://forum.djangoproject.com/t/error-no-such-table/5632/3 "2020-12-09T20:00:20Z")

</div>

Yes

> (env) isaev@web:~/plg/www$ python manage.py makemigrations  
> No changes detected  
> (env) isaev@web:~/plg/www$ python manage.py migrate  
> Operations to perform:  
> Apply all migrations: admin, auth, contenttypes, sessions  
> Running migrations:  
> Applying contenttypes.0001\_initial… OK  
> Applying admin.0001\_initial… OK  
> Applying admin.0002\_logentry\_remove\_auto\_add… OK  
> Applying admin.0003\_logentry\_add\_action\_flag\_choices… OK  
> Applying contenttypes.0002\_remove\_content\_type\_name… OK  
> Applying auth.0001\_initial… OK  
> Applying auth.0002\_alter\_permission\_name\_max\_length… OK  
> Applying auth.0003\_alter\_user\_email\_max\_length… OK  
> Applying auth.0004\_alter\_user\_username\_opts… OK  
> Applying auth.0005\_alter\_user\_last\_login\_null… OK  
> Applying auth.0006\_require\_contenttypes\_0002… OK  
> Applying auth.0007\_alter\_validators\_add\_error\_messages… OK  
> Applying auth.0008\_alter\_user\_username\_max\_length… OK  
> Applying auth.0009\_alter\_user\_last\_name\_max\_length… OK  
> Applying auth.0010\_alter\_group\_name\_max\_length… OK  
> Applying auth.0011\_update\_proxy\_permissions… OK  
> Applying auth.0012\_alter\_user\_first\_name\_max\_length… OK  
> Applying sessions.0001\_initial… OK

And I don’t see table ‘www\_user’ in my database (

> sqlite\> .open db.sqlite3  
> sqlite\> .tables  
> auth\_group django\_admin\_log django\_session  
> auth\_group\_permissions django\_content\_type  
> auth\_permission django\_migrations  
> sqlite\>

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 9, 2020, 8:02pm UTC](https://forum.djangoproject.com/t/error-no-such-table/5632/4 "2020-12-09T20:02:30Z")

</div>

So you can see that you don’t have a migration for app www - the easiest way to fix this is by specifying the app name on your [makemigrations](https://docs.djangoproject.com/en/3.1/ref/django-admin/#makemigrations) command:  
`manage.py makemigrations www`

---

<div class="post-metadata">

**Author:** ![bouseman](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/bouseman/32/2771_2.png) [@bouseman](https://forum.djangoproject.com/u/bouseman)\
**Post date:** [December 9, 2020, 8:07pm UTC](https://forum.djangoproject.com/t/error-no-such-table/5632/5 "2020-12-09T20:07:31Z")

</div>

You’re a genius. Everything worked ) Thanks a lot

---

<div class="post-metadata">

**Author:** ![ahmedtarekmoftah](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ahmedtarekmoftah/32/3096_2.png) [@ahmedtarekmoftah](https://forum.djangoproject.com/u/ahmedtarekmoftah)\
**Post date:** [January 11, 2021, 6:50pm UTC](https://forum.djangoproject.com/t/error-no-such-table/5632/6 "2021-01-11T18:50:37Z")

</div>

you helped me. thanks

---

<div class="post-metadata">

**Author:** ![mubashir-v](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mubashir-v/32/6642_2.png) [@mubashir-v](https://forum.djangoproject.com/u/mubashir-v)\
**Post date:** [December 28, 2021, 2:39pm UTC](https://forum.djangoproject.com/t/error-no-such-table/5632/7 "2021-12-28T14:39:18Z")

</div>

Hi @KenWhitesell ,

I am getting same error on makemigrations call .

getting error as follow  
`django.db.utils.OperationalError: no such table: app_mynewmodel`

And error is throwing from view.py at following point :-

`if MyNewModel.objects.filter().exist():`

If I remove the code line above, I can see that the migration is successful .It seems like issue with `exist()` call . Is this expected error ?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 28, 2021, 3:02pm UTC](https://forum.djangoproject.com/t/error-no-such-table/5632/8 "2021-12-28T15:02:17Z")

</div>

This is likely a different problem - please open a new topic to discuss it, along with posting the complete view causing this issue. Also, provide a brief description of what you had done up to this point. (Is this the first makemigrations for this project? Was it working before adding that line of code?)

---

<div class="post-metadata">

**Author:** ![CoderLalit](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/coderlalit/32/7199_2.png) [@CoderLalit](https://forum.djangoproject.com/u/CoderLalit)\
**Post date:** [January 25, 2022, 9:55am UTC](https://forum.djangoproject.com/t/error-no-such-table/5632/9 "2022-01-25T09:55:42Z")

</div>

I also have same problem, makemigration app\_name ran successfully but the error still exists  
please help me too. I deleted all previous migrations and ran makemigrations and migrate commands again but still the same problem

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 25, 2022, 12:01pm UTC](https://forum.djangoproject.com/t/error-no-such-table/5632/10 "2022-01-25T12:01:02Z")

</div>

This is likely a different problem than the ones discussed previously - please open a new topic to discuss it

---

<div class="post-metadata">

**Author:** ![Goz1e](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/goz1e/32/9888_2.png) [@Goz1e](https://forum.djangoproject.com/u/Goz1e)\
**Post date:** [August 29, 2022, 3:23pm UTC](https://forum.djangoproject.com/t/error-no-such-table/5632/11 "2022-08-29T15:23:05Z")

</div>

Hi,  
i have been struggling with the same problem, could you please let me know if you were able to fix this. ‘manage.py makemigrations appname’ did not work for me

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 29, 2022, 4:10pm UTC](https://forum.djangoproject.com/t/error-no-such-table/5632/12 "2022-08-29T16:10:37Z")

</div>

This is likely a different problem than the ones discussed previously - please open a new topic to discuss it.  
Provide a brief description of your project and what you have done up to this point along with the relevant details of the error you’re encountering. (Is this the first makemigrations for this project? Did it ever work?)
