0

I get the following error while trying to run the command python manage.py makemigrations invigilators:

django.db.utils.ProgrammingError: (1146, "Table 'mydatabase.invigilators_shift' doesn't exist")

class Shift(models.Model):
    shiftName = models.CharField(max_length=255,blank=False,unique=True)
    exam = models.ForeignKey(Exam,on_delete=models.CASCADE,related_name="shifts")
    startTime = models.TimeField()
    endTime = models.TimeField()

    def __str__(self):
        return self.shiftName

I have already cleared all previous migrations and an empty database is already created.

shaedrich
  • 4,826
  • 2
  • 26
  • 35
sk_462
  • 487
  • 1
  • 6
  • 14
  • https://stackoverflow.com/questions/27583744/django-table-doesnt-exist – Jagjeet Singh Jan 11 '19 at 09:26
  • 1
    You have code that is trying to query the database before `makemigrations` runs. [Here is a similar question](https://stackoverflow.com/questions/45153674/programmingerror-relation-blah-blah-does-not-exist-trying-to-run-the-specifi). To help with your specific problem, you need to show the full traceback which will show where the query is occuring. – Alasdair Jan 11 '19 at 10:32

3 Answers3

2

Try running these commands

  • python manage.py migrate <app_name> zero
  • delete all initial.py file under app migrations
  • python manage.py makemigrations
  • python manage.py migrate
Anshu Pal
  • 31
  • 3
0

In my case I get the table doesn't exist errors from forms.py. I then comment out the entries in forms.py that refer to a database table. Then I can run makemigrations and migrate. Then uncomment the lines and everything works. This has plagued me for multiple Django releases.

obotezat
  • 906
  • 13
  • 18
A. Beckman
  • 1
  • 2
  • 2
-1

First Step: Just "Cut" The all models from Models.py & paste that models to the any other text file or notepad.

Second Step: Just "Cut" the all forms from forms.py & paste at the the same text file at you pasted the Models.

Third Step: Make a Comment of all imported models & forms in views.py Because we don't want errors.

Fourth Step: After these three steps you have to just run the command "python manage.py migrate".

Fifth Step: After that command You have to just bring back all the models in models.py and all the forms in forms.py & uncomment all the imported forms and models of views.py.

Last Step: After these all steps you have to just run another two commands 1."python manage.py makemigrations" 2."python manage.py migrate"

& Done,It works.

  • Please avoid such detailed list of steps: "copy", "cut" and "comment" are not useful. Your list cannot be generalized as a good procedure as it is very close to your specific case and very vague "Make a Comment [...] Because we don't want errors". Be simple and provide examples. Hope that my comment can help you :) – Dos Aug 05 '21 at 10:42
  • okay thanks for your comment, But it works. – Aryan sanchiya Aug 05 '21 at 17:21