Django model with mysql

Hello guys, when i was deploying my project to google app engine i have a problem. At google cloud there is no sqlite so i searched and changed my database to Mysql. And i did everything correct. But when i was creating tables at Google Cloud Mysql i’ve a stupid error:
django.db.utils.OperationalError: (1118, ‘Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs’)

I searched on internet and i saw somethings but i couldn’t solve it. So what i did:
i changed all my string types to something and for final i changed everything to TextField to solve but nothing solved.

But i think where is the problem but i’m not sure and i don’t want to do anything without being sure. One of my models have ~30 columun (With model-translation columuns) and maybe it’s too big for the table type of MySql but i’m not sure. And changing this table is so hard because this table-model is product detail table so it’s so hard. So please help. (i didn’t copy-paste my model here because it’s too big but if you want i can.)

If we’re going to try and offer suggestions for improvements, we’re going to need to see the model. Don’t worry about it’s size, just make sure that when you post it, you enclose it between lines of three backtick - ` characters.

from product.choices import Aydinlatma_Secenek, Boya_Secenek, Calisma_Alani_Hammadde_Secenek, Cekmece_Ray_Secenek, Hammadde_Secenek, Kilit_Secenek, Panel_Secenek, Teker_Ayak_Secenek
from django.db import models
from django.template.defaultfilters import slugify
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django.core.validators import MaxValueValidator,MinValueValidator

class Buyuk_Urun_Cesitleri(models.Model):
    Isim = models.TextField(verbose_name="İsim")
    Resim = models.ImageField(null=True,blank=True, upload_to="BuyukUrunCesitleri/")    
    Link = models.SlugField(unique=True)

    def admin_resim(self):                       
        return mark_safe('<img src="{}" width="150" height="150" style="object-fit:contain" />'.format(self.Resim.url))
    admin_resim.allow_tags = True
    admin_resim.short_description = ' Resim 1'
    def save(self, *args, **kwargs):
        self.Link = slugify(self.Isim)
        super(Buyuk_Urun_Cesitleri, self).save(*args, **kwargs)

    class Meta:
        ordering = ['id']
        verbose_name = "Büyük Ürün Çeşidi"
        verbose_name_plural = "Büyük Ürün Çeşitleri"

    def __str__(self):
        return self.Isim

class Bize_Ulasin(models.Model): 
    Isim = models.TextField(verbose_name="İsim",null=True,blank=True)  
    E_mail = models.EmailField(verbose_name="E-mail",null=True,blank=True)
    Konu = models.TextField(verbose_name="Konu",null=True,blank=True)
    Mesaj = models.TextField(verbose_name="Mesaj",null=True,blank=True)

    class Meta:
        ordering = ['-id']
        verbose_name = "Bize Ulaşın Gelen Mesajlar"
        verbose_name_plural = "Gelen Mesajlar"

class Gizlilik_Ve_Guvenlik_Politikasi(models.Model): 
    Paragraf_1 = models.TextField(verbose_name="Paragraf 1",null=True,blank=True)

    class Meta:
        verbose_name = "Gizlilik ve Güvenlik Politikası"
        verbose_name_plural = "Gizlilik ve Güvenlik Politikası"

    def __str__(self):
        return "Gizlilik ve Güvenlik Politikası"

class Hizmetlerimiz(models.Model): 
    Link = models.SlugField(unique=True)
    Baslik_1 = models.TextField(verbose_name="Başlık 1",null=True,blank=True)
    Paragraf_1 = models.TextField(verbose_name="Paragraf 1",null=True,blank=True)
    Paragraf_2 = models.TextField(verbose_name="Paragraf 2",null=True,blank=True)        Resim_1 = models.ImageField(verbose_name="Resim 1",null=True,blank=True, upload_to="Hizmetlerimiz/")        Resim_2 = models.ImageField(verbose_name="Resim 2",null=True,blank=True, upload_to="Hizmetlerimiz/")        Resim_3 = models.ImageField(verbose_name="Resim 3",null=True,blank=True, upload_to="Hizmetlerimiz/")        Resim_4 = models.ImageField(verbose_name="Resim 4",null=True,blank=True, upload_to="Hizmetlerimiz/")        Resim_5 = models.ImageField(verbose_name="Resim 5",null=True,blank=True, upload_to="Hizmetlerimiz/")

    class Meta:
        ordering = ['Baslik_1']
        verbose_name = "Hizmet İsmi"
        verbose_name_plural = "Hizmetlerimiz"

    def save(self, *args, **kwargs):
        self.Link = slugify(self.Baslik_1)
        super(Hizmetlerimiz, self).save(*args, **kwargs)

    def __str__(self):
        return self.Baslik_1

class Kataloglar(models.Model):        Katalog = models.FileField(verbose_name="Katalog",null=True,blank=True, upload_to="Kataloglar/")       
    class Meta:
        verbose_name = "Katalog"
        verbose_name_plural = "Kataloglar"       

class Proje_Isleri(models.Model):
    Isim = models.TextField(verbose_name="İsim",null=True,blank=True)        Proje_Resim_1 = models.ImageField(verbose_name="Proje Resim 1",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_2 = models.ImageField(verbose_name="Proje Resim 2",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_3 = models.ImageField(verbose_name="Proje Resim 3",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_4 = models.ImageField(verbose_name="Proje Resim 4",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_5 = models.ImageField(verbose_name="Proje Resim 5",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_6 = models.ImageField(verbose_name="Proje Resim 6",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_7 = models.ImageField(verbose_name="Proje Resim 7",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_8 = models.ImageField(verbose_name="Proje Resim 8",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_9 = models.ImageField(verbose_name="Proje Resim 9",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_10 = models.ImageField(verbose_name="Proje Resim 10",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_11 = models.ImageField(verbose_name="Proje Resim 11",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_12 = models.ImageField(verbose_name="Proje Resim 12",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_13 = models.ImageField(verbose_name="Proje Resim 13",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_14 = models.ImageField(verbose_name="Proje Resim 14",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_15 = models.ImageField(verbose_name="Proje Resim 15",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_16 = models.ImageField(verbose_name="Proje Resim 16",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_17 = models.ImageField(verbose_name="Proje Resim 17",null=True,blank=True, upload_to="ProjeIsleri/")        Proje_Resim_18 = models.ImageField(verbose_name="Proje Resim 18",null=True,blank=True, upload_to="ProjeIsleri/")

    def admin_resim(self):                       
        return mark_safe('<img src="{}" width="150" height="150" style="object-fit:contain" />'.format(self.Proje_Resim_1.url))
    admin_resim.allow_tags = True
    admin_resim.short_description = ' Resim 1'

    class Meta:
        ordering = ['Isim']
        verbose_name = "Proje İşi İsmi"
        verbose_name_plural = "Proje İşleri"

class Sertifikalar(models.Model):        Sertifika_Resim = models.ImageField(verbose_name="Sertifika Resim 1",null=True,blank=True, upload_to="Sertifikalar/")
    def admin_resim(self):                       
        return mark_safe('<img src="{}" width="150" height="150" style="object-fit:contain" />'.format(self.Sertifika_Resim.url)) 
    admin_resim.allow_tags = True
    admin_resim.short_description = ' Resim'

    class Meta:
        ordering = ['id']
        verbose_name = "Sertifika"
        verbose_name_plural = "Sertifikalar"

class GSlayt(models.Model):        Slayt_Resim = models.ImageField(verbose_name="Slayt Resim",null=True,blank=True, upload_to="Slaytlar/")

    def admin_resim(self):                       
        return mark_safe('<img src="{}" width="150" height="150" style="object-fit:contain" />'.format(self.Slayt_Resim.url))
    admin_resim.allow_tags = True
    admin_resim.short_description = 'Resim 1'

    class Meta:
        ordering = ['id']
        verbose_name = "Slayt"
        verbose_name_plural = "Slaytlar"

class Sik_Sorulan_Sorular(models.Model):
    Soru = models.TextField(null=True,blank=True)
    Cevap = models.TextField(null=True,blank=True)

    class Meta:
        ordering = ['id']
        verbose_name = "Sık Sorulan Soru"
        verbose_name_plural = "Sık Sorulan Sorular"

    def __str__(self):
        return self.Soru

class Urun_Cesitleri(models.Model):
    Isim = models.TextField(verbose_name="İsim")
    Ust_Kategori = models.ManyToManyField(Buyuk_Urun_Cesitleri, default="5")
    Resim = models.ImageField(null=True,blank=True, upload_to="UrunCesitleri/")
    Link = models.SlugField(unique=True)

    def admin_resim(self):                       
        return mark_safe('<img src="{}" width="150" height="150" style="object-fit:contain" />'.format(self.Resim.url))
    admin_resim.allow_tags = True
    admin_resim.short_description = ' Resim 1'

    def save(self, *args, **kwargs):
        self.Link = slugify(self.Isim)
        super(Urun_Cesitleri, self).save(*args, **kwargs)        

    class Meta:
        ordering = ['Isim']
        verbose_name = "Ürün Çeşidi"
        verbose_name_plural = "Ürün Çeşitleri"

    def __str__(self):
        return self.Isim

class Urun_Istek(models.Model): 
    Isim = models.TextField(verbose_name="İsim")  
    E_mail = models.EmailField(verbose_name="E-mail",null=True,blank=True)
    Firma = models.TextField(verbose_name="Firma İsmi",null=True,blank=True)
    Urun = models.TextField(verbose_name="Ürün",null=True,blank=True)
    Ek_Istek = models.TextField(verbose_name="Ek İstek",null=True,blank=True)

    class Meta:
        ordering = ['-id']
        verbose_name = "Ürün İstek Formları"
        verbose_name_plural = "Ürün İstekleri"       

class Sirket_Profili(models.Model):        Hakkimizda_Baslik = models.TextField(verbose_name="Hakkımızda Başlık",null=True,blank=True)        Hakkimizda_Paragraf = models.TextField(verbose_name="Hakkımızda Paragraf",null=True,blank=True)        Hakkimizda_Resim = models.ImageField(verbose_name="Hakkımızda Resim",null=True,blank=True,upload_to="SirketProfili/")        Misyon_Baslik = models.TextField(verbose_name="Misyon Başlık",null=True,blank=True)
    Misyon_Paragraf = models.TextField(verbose_name="Misyon Paragraf",null=True,blank=True)        Misyon_Resim = models.ImageField(verbose_name="Misyon Resim",null=True,blank=True,upload_to="SirketProfili/")
    Vizyon_Baslik = models.TextField(verbose_name="Vizyon Başlık",null=True,blank=True)
    Vizyon_Paragraf = models.TextField(verbose_name="Vizyon Paragraf",null=True,blank=True)        Vizyon_Resim = models.ImageField(verbose_name="Vizyon Resim",null=True,blank=True,upload_to="SirketProfili/")        

    class Meta:
        verbose_name = "Şirket Profili"
        verbose_name_plural = "Şirket Profili"

class Abone_Mail_Liste(models.Model): 
    E_mail = models.EmailField(verbose_name="E-mail",null=True,blank=True)

    class Meta:
        ordering = ['-id']
        verbose_name = "Abone-Mail Listesi"
        verbose_name_plural = "Mailler"

And my big model is here and i think problem is in here

class Urunler(models.Model):       
    Urun_Kodu =                models.TextField         (verbose_name="Ürün Kodu",                  null=True,blank=True,   default="DK-")    
    Urun_Seviye =              models.BooleanField      (verbose_name="Ürün Seviyesi",                                      default="True",                     help_text="Eğer Alt Ürünse İşareti Kaldırınız.")
    M_Aciklama =               models.TextField         (verbose_name="Meta Açıklama",              null=True,blank=True,   default='Denka')    
    Urun_Cesitleri =           models.ManyToManyField   (Urun_Cesitleri,                                                    default="23")        Dis_Olcusu =               models.TextField         (verbose_name="Dış Ölçüsü",                 null=True,blank=True,   default='',       help_text="EnxYükseklikxDerinlik şeklinde girilmesi gerekmektedir.")
    Govde_Boya =               models.PositiveSmallIntegerField (verbose_name="Gövde Boya",                 default='1',      choices=Boya_Secenek)
    Toplam_Agirlik =           models.TextField         (verbose_name="Toplam Ağırlık",             null=True,blank=True,   default='50 Kg')
    Toplam_Kapasite =          models.TextField         (verbose_name="Toplam Kapasite",            null=True,blank=True,   default='200 Kg')
    Hammaddesi =               models.PositiveSmallIntegerField (verbose_name="Hammadde",                   default='1',      choices=Hammadde_Secenek)
    Calisma_Alani_Hammaddesi = models.PositiveSmallIntegerField (verbose_name="Çalışma Alanı Hammaddesi",   default='0',      choices=Calisma_Alani_Hammadde_Secenek)    
    Cekmece_Sayisi =           models.PositiveSmallIntegerField (verbose_name="Çekmece Sayısı",             default='0',      validators=[MinValueValidator(0), MaxValueValidator(100)])
    Cekmece_Olcusu =           models.TextField         (verbose_name="Çekmece Ölçüsü",             null=True,blank=True,   default='-',      help_text="EnxYükseklikxDerinlik şeklinde girilmesi gerekmektedir.")
    Cekmece_Boya =             models.PositiveSmallIntegerField (verbose_name="Çekmece Boya",               default='0',      choices=Boya_Secenek)
    Cekmece_Acilabilirligi =   models.TextField         (verbose_name="Çekmece Açılma Kapasitesi",  null=True,blank=True,   default='100%')
    Max_Cekmece_Kapasitesi =   models.TextField         (verbose_name="Max. Çekmece Kapasitesi",    null=True,blank=True,   default='-')
    Cekmece_Ray_Sistemi =      models.PositiveSmallIntegerField (verbose_name="Çekmece Ray Sistemi",        default='0',      choices=Cekmece_Ray_Secenek)    
    Dolap_Sayisi =             models.PositiveSmallIntegerField (verbose_name="Dolap Sayısı",               default='0',      validators=[MinValueValidator(0), MaxValueValidator(100)])
    Dolap_Olcusu =             models.TextField         (verbose_name="Dolap Ölçüsü",               null=True,blank=True,   default='-',      help_text="EnxYükseklikxDerinlik şeklinde girilmesi gerekmektedir.")
    Dolap_Boya =               models.PositiveSmallIntegerField (verbose_name="Dolap Boya",                 default='0',      choices=Boya_Secenek)
    Max_Dolap_Kapasitesi =     models.TextField         (verbose_name="Max. Dolap Kapasitesi",      null=True,blank=True,   default='-')
    Raf_Sayisi =               models.PositiveSmallIntegerField (verbose_name="Raf Sayısı",                 default='0',      validators=[MinValueValidator(0), MaxValueValidator(100)])
    Raf_Olcusu =               models.TextField         (verbose_name="Raf Ölçüsü",                 null=True,blank=True,   default='-',   help_text="EnxYükseklikxDerinlik şeklinde girilmesi gerekmektedir.")
    Raf_Boya =                 models.PositiveSmallIntegerField (verbose_name="Raf Boya",                   default='0',      choices=Boya_Secenek)
    Max_Raf_Kapasitesi =       models.TextField         (verbose_name="Max. Raf Kapasitesi",        null=True,blank=True,   default='-')    
    Panel =                    models.PositiveSmallIntegerField (verbose_name="Panel",                      default='0',      choices=Panel_Secenek)
    Panel_Olcusu =             models.TextField         (verbose_name="Panel Ölçüsü",               null=True,blank=True,   default='-',   help_text="EnxYükseklikxDerinlik şeklinde girilmesi gerekmektedir.")
    Aydinlatma =               models.PositiveSmallIntegerField (verbose_name="Aydınlatma",                 default='0',      choices=Aydinlatma_Secenek)
    Kilit =                    models.PositiveSmallIntegerField (verbose_name="Kilit Tipi",                 default='0',      choices=Kilit_Secenek)
    Teker_Ayak_Sistemi =       models.PositiveSmallIntegerField (verbose_name="Tekerlek Sistemi",           default='0',      choices=Teker_Ayak_Secenek)
    Teker_Ayak_Caplari =       models.TextField         (verbose_name="Tekerlek Çapları",           null=True,blank=True,   default='Q100')
    Avadanlik_Sayisi =         models.PositiveSmallIntegerField (verbose_name="Avadanlık Sayısı",           default='0',      validators=[MinValueValidator(0), MaxValueValidator(100)])
    Avadanlik_Olcusu =         models.TextField            (verbose_name="Avadanlık Ölçüsü",           null=True,blank=True,   default='-',   help_text="EnxYükseklikxDerinlik şeklinde girilmesi gerekmektedir.")
    Mors_Sayisi =              models.PositiveSmallIntegerField (verbose_name="Mors Sayısı",                default='0',      validators=[MinValueValidator(0), MaxValueValidator(100)])    
    Resim =                    models.ImageField        (verbose_name="Resim",                      null=True,blank=True,   upload_to="Urunler/")
    Resim2 =                   models.ImageField        (verbose_name="Resim 2",                    null=True,blank=True,   upload_to="Urunler/")
    Resim3 =                   models.ImageField        (verbose_name="Resim 3",                    null=True,blank=True,   upload_to="Urunler/")    
    trendyol_link =            models.URLField          (verbose_name="Trendyol Linki",             null=True,blank=True)
    hepsiburada_link =         models.URLField          (verbose_name="Hepsiburada Linki",          null=True,blank=True)
    n11_link =                 models.URLField          (verbose_name="N11 Linki",                  null=True,blank=True)

    def admin_resim(self):                       
        return mark_safe('<img src="{}" width="150" height="150" style="object-fit:contain" />'.format(self.Resim.url))
    admin_resim.allow_tags = True
    admin_resim.short_description = ' Resim 1'

    class Meta:
        ordering = ['Urun_Kodu']
        verbose_name = "Ürün"
        verbose_name_plural = "Ürünler"

And if you want to check i found something on docs of django. Databases | Django documentation | Django maybe this can help but i didn’t understand

I don’t see anything wrong with the table itself. While a 30-column table may be larger than the typical table, it shouldn’t be a problem of its own. Since there’s nothing obviously-to-me wrong, some more information may help.

What was the operation being performed when this error occurred? Were you doing a migration? Entering some data? Importing data?

Can we see the complete traceback of the error?

Also, after you changed the field type in the model, did you do a makemigrations then migrate?

Can you post the schema for that table?

Man i don’t know i can fully answer your questions but here what i’ve done:
i change my database at settings to google mysql thing and the tutorial that i watch said i need to makemigrations and migrate. And i’ve some errors because of loading mysql but i solved it. Then i try to python manage.py makemigrations and it accept but when i try to python manage.py migrate i got this error:

The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “C:\Users\TKA\Desktop\DenkaMetal\manage.py”, line 21, in
main()
File “C:\Users\TKA\Desktop\DenkaMetal\manage.py”, line 17, in main
execute_from_command_line(sys.argv)
File “C:\Python39\lib\site-packages\django\core\management_init_.py”, line 401, in execute_from_command_line
utility.execute()
File “C:\Python39\lib\site-packages\django\core\management_init_.py”, line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “C:\Python39\lib\site-packages\django\core\management\base.py”, line 330, in run_from_argv
self.execute(*args, **cmd_options)
File “C:\Python39\lib\site-packages\django\core\management\base.py”, line 371, in execute
output = self.handle(*args, **options)
File “C:\Python39\lib\site-packages\django\core\management\base.py”, line 85, in wrapped
res = handle_func(*args, **kwargs)
File “C:\Python39\lib\site-packages\django\core\management\commands\migrate.py”, line 243, in handle
post_migrate_state = executor.migrate(
File “C:\Python39\lib\site-packages\django\db\migrations\executor.py”, line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File “C:\Python39\lib\site-packages\django\db\migrations\executor.py”, line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File “C:\Python39\lib\site-packages\django\db\migrations\executor.py”, line 227, in apply_migration
state = migration.apply(state, schema_editor)
File “C:\Python39\lib\site-packages\django\db\migrations\migration.py”, line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File “C:\Python39\lib\site-packages\django\db\migrations\operations\models.py”, line 92, in database_forwards
schema_editor.create_model(model)
File “C:\Python39\lib\site-packages\django\db\backends\base\schema.py”, line 324, in create_model
self.execute(sql, params or None)
File “C:\Python39\lib\site-packages\django\db\backends\base\schema.py”, line 142, in execute
cursor.execute(sql, params)
File “C:\Python39\lib\site-packages\django\db\backends\utils.py”, line 98, in execute
return super().execute(sql, params)
File “C:\Python39\lib\site-packages\django\db\backends\utils.py”, line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File “C:\Python39\lib\site-packages\django\db\backends\utils.py”, line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File “C:\Python39\lib\site-packages\django\db\backends\utils.py”, line 84, in _execute
return self.cursor.execute(sql, params)
File “C:\Python39\lib\site-packages\django\db\utils.py”, line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File “C:\Python39\lib\site-packages\django\db\backends\utils.py”, line 82, in _execute
return self.cursor.execute(sql)
File “C:\Python39\lib\site-packages\django\db\backends\mysql\base.py”, line 73, in execute
return self.cursor.execute(query, args)
File “C:\Python39\lib\site-packages\pymysql\cursors.py”, line 148, in execute
result = self._query(query)
File “C:\Python39\lib\site-packages\pymysql\cursors.py”, line 310, in _query
conn.query(q)
File “C:\Python39\lib\site-packages\pymysql\connections.py”, line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “C:\Python39\lib\site-packages\pymysql\connections.py”, line 775, in _read_query_result
result.read()
File “C:\Python39\lib\site-packages\pymysql\connections.py”, line 1156, in read
first_packet = self.connection._read_packet()
File “C:\Python39\lib\site-packages\pymysql\connections.py”, line 725, in _read_packet
packet.raise_for_error()
File “C:\Python39\lib\site-packages\pymysql\protocol.py”, line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File “C:\Python39\lib\site-packages\pymysql\err.py”, line 143, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.OperationalError: (1118, ‘Row size too large. The maximum row size for the used table type, not counting
BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs’)

I solved it, there was a 200+ folder in migrations and pycache docs. And i think i tried everything and now its my last bullet and i don’t have anything to lose and i delete them all. Now i can do whatever i want.

1 Like