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

Hi there,
I am trying to make migrations by running the following command:

python makemigrations

But, I am getting the error like this:

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

I am using MySQL Database named as dinsos.

Earlier my app was working fine with all the user migrations and stuff. When I made this new Model Anggota and I also did zero migration on mapping app, I am getting the above mentioned error.

My mapping.models is below:

class Anggota(models.Model):
  def __str__(self):
    return "{}.".format(self.nama_anggota)
class Penerima(models.Model):
  id_anggota=models.ForeignKey(Anggota, on_delete=models.CASCADE)
  nama = models.CharField(max_length=255)
  alamat = models.CharField(max_length=255)
  kabupaten = models.CharField(max_length=255)
  kecamatan = models.ForeignKey(Kecamatan, on_delete=models.CASCADE)
  desa = models.CharField(max_length=255)
  latitude = models.FloatField(blank=True, null=True)
  longitude = models.FloatField(blank=True, null=True)
  jumlah_menerima = models.IntegerField(default=0, null=True)
  foto_bukti = models.CharField(max_length=255, blank=True, null=True)
  tahun = models.CharField(max_length=10, blank=True, null=True)
  bansos = models.ForeignKey(Bansos, on_delete=models.CASCADE, null=True)
  date = models.DateTimeField(auto_now_add=True, blank=True)

  def save(self, *args, **kwargs):
    if self.latitude is None and self.longitude is None:  
      location = geocoder.osm(self.desa+" "+self.kabupaten)
      self.latitude =
      self.longitude = location.lng
    super(Penerima, self).save(*args, **kwargs)

  def __str__(self):
    return "{}. {}".format(, self.nama)

my mapping.filters is below:

class PenerimaFilter(django_filters.FilterSet):
    b = []
    k = []
    t = []
    for i in Penerima.objects.values_list('tahun', flat=True).order_by('tahun').distinct():
    for i in Bansos.objects.all().order_by('nama_bansos'):
    for i in Kecamatan.objects.all().order_by('nama_kecamatan'):
    tahun = django_filters.ChoiceFilter(
        choices=t, label="", empty_label="Semua", 
        widget=forms.Select(attrs={'class': 'form-control', 'style':'border-color: #063970;border-radius: 10px;color: #063970'})
    bansos = django_filters.ChoiceFilter(
        choices=b, label="", empty_label="Semua",
        widget=forms.Select(attrs={'class': 'form-control', 'style':'border-color: #063970;border-radius: 10px;color: #063970'})
    kecamatan = django_filters.ChoiceFilter(
        choices=k, label="", empty_label="Semua",
        widget=forms.Select(attrs={'class': 'form-control', 'style':'border-color: #063970;border-radius: 10px;color: #063970'})
    class Meta:

please help me, i’m so frustrated TT TT thanks!!

What specifically are you saying you did here? If you backed out previously run migrations, you should run a migrate before trying to make new migrations.

Also note, you have:

You’re trying to execute queries at the module level of your code. Unless you know exactly what you are doing and what the side-effects are of doing this, this is a mistake.
Queries should not be run outside the context of a function in Django.

it was my fault when doing zero migrations. I just tried the command and it messed things up. what should I do? I’m a newbie, please help me

I also got the same error when I run a migrate command T_T

do I have to put those queries inside the class meta?

Unfortunately, I don’t have any direct knowledge of that third-party package (django-filters), I don’t know what the appropriate solution would be for it.

You might be able to put that code into the __init__ method for that object and save those lists as instance attributes - but that’s just a guess.

thanks Ken, I fixed the error by comment out the mapping.filters and then run migrate command