0

I would like to update max length of django char field of base model and overwrite it in a concrete model that extends from parent, but when i execute migrate command on heroku bash cli appears this error:

django.db.utils.OperationalError: cannot ALTER TABLE "cms_categoria" because it has pending trigger events

Here i leave the change:

Before

class Entidad(models.Model):
  titulo = models.CharField(verbose_name=_("Título"), max_length=100)
  ...

class Categoria(Entidad):
  ...

************

After

class Entidad(models.Model):
  titulo = models.CharField(verbose_name=_("Título"), max_length=30)

class Categoria(Entidad):
  titulo = models.CharField(max_length=20)
  ...

How should I do the update ? Anybody could help me ? Thanks

  • 1
    1. make changes in models.py 2. create migration file using `makemigration` command 3. Push your changes to Heroku 4. Get into the server and migrate the DB using `migrate` command – JPG Sep 23 '19 at 08:05
  • @JPG that is that I’m doing, but the migarte command on Heroku cli through this error – Alberto Sanmartin Martinez Sep 23 '19 at 08:08
  • 1
    A bit explaining 2, 3 and 4 in @JPG comment, on your local machine you run `python manage.py makemigrations`, that will create a migration file, then you push the file to heroku, after that in heroku bash run `python manage.py migrate` – Moha369 Sep 23 '19 at 08:10
  • i'm doing that, after all those steps, when i run on heroku cli **python mange.py migrate** appears the error. – Alberto Sanmartin Martinez Sep 23 '19 at 08:13
  • Related post, https://stackoverflow.com/q/12838111/8283848 – JPG Sep 23 '19 at 08:14
  • **python manage.py schemamigration cms --auto** through **Unknown command: 'schemamigration'. Did you mean showmigrations?**. Seems that this command not exist. how i will should to do the schema migration change ? – Alberto Sanmartin Martinez Sep 23 '19 at 08:31
  • There might be reason that, "titulo" field has more character in there rows in Db. And now you are trying to reduce the size. It's an suggestion to you can you check the maximum length of the value in the column like.. "SELECT MAX(LENGTH(titulo)) FROM Entidad" – Vivek Sep 23 '19 at 08:50
  • @Vivek i checked the length of all cms_categoria objects and changed to new max length migration and the errors persist. – Alberto Sanmartin Martinez Sep 23 '19 at 09:33

0 Answers0