Table thumbnail_kvstore doesn't exist
Asked Answered
B

4

20

I can't get the thumbnail displayed in my template. I get this error:

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

  • Installed sorl_thumbnail-12.3
  • I'm using MariaDB 10.1.11
  • I have no migration that are not executed
  • I can see the image if I don't use the 'thumbnail' tag

Here is what I did

  • In settings.py:

    INSTALLED_APPS = [
        ...
        'sorl.thumbnail',
    ]
    
    THUMBNAIL_DEBUG = TRUE
    
  • In models.py

    import sorl
    ...
        image = sorl.thumbnail.ImageField(upload_to='thumbnails', null=True)
    
  • In my template

    {% thumbnail content.image "237x110" as im %}
        <img src="{{ im.url }}">
    {% endthumbnail %}
    
Behave answered 1/2, 2016 at 17:15 Comment(0)
S
38

So after some research, it looks like the version 12.3 of sorl-thumbnail on PyPI and Github are different!

If you download the source directly from PyPI - you will find that the package doesn't contain any migrations. This is the reason the table doesn't exist even though you've run all the migrations.

On Github, the migration file for version 12.3 definitely exists.

You have three options:

  1. Create the table using ./manage.py syncdb (only if you're running Django 1.8 or below)
  2. Install directly from Github for version 12.3
  3. Use version 12.4a1 of sorl-thumbnail which includes migrations

You can install from Github directly as follows:

pip install git+git://github.com/mariocesar/[email protected]

sorl-thumbnail version 12.3 supports up to Django version 1.8, where the syncdb command still exists. If you're running Django 1.8 or lower, you can create the missing table by running

python manage.py syncdb
Sugihara answered 2/2, 2016 at 1:53 Comment(2)
Ok thanks this works. As I am using Django 1.9.1 I ran ./manage.py migrate after having installed the version 12.3 from git.Behave
Please see answer from AlmasK89 below for running makemigrations in Django 1.9 or higher: https://mcmap.net/q/609149/-table-thumbnail_kvstore-doesn-39-t-existAthena
U
53

If just

manage.py makemigrations 

doesn't create any migrations, try

manage.py makemigrations thumbnail 
manage.py migrate

This will create migrations for thumbnail and then migrate them. It works for me. I am using Django 1.9 and sorl.thumbnail 12.3.

Ursala answered 9/3, 2016 at 5:49 Comment(2)
I cannot find this in the documentation - but it worksConvexity
You can read more here docs.djangoproject.com/ja/1.9/topics/migrations/… and here docs.djangoproject.com/ja/1.9/ref/django-admin/… Shortly, we use application label to show django from what application migrations must be generated.Ursala
S
38

So after some research, it looks like the version 12.3 of sorl-thumbnail on PyPI and Github are different!

If you download the source directly from PyPI - you will find that the package doesn't contain any migrations. This is the reason the table doesn't exist even though you've run all the migrations.

On Github, the migration file for version 12.3 definitely exists.

You have three options:

  1. Create the table using ./manage.py syncdb (only if you're running Django 1.8 or below)
  2. Install directly from Github for version 12.3
  3. Use version 12.4a1 of sorl-thumbnail which includes migrations

You can install from Github directly as follows:

pip install git+git://github.com/mariocesar/[email protected]

sorl-thumbnail version 12.3 supports up to Django version 1.8, where the syncdb command still exists. If you're running Django 1.8 or lower, you can create the missing table by running

python manage.py syncdb
Sugihara answered 2/2, 2016 at 1:53 Comment(2)
Ok thanks this works. As I am using Django 1.9.1 I ran ./manage.py migrate after having installed the version 12.3 from git.Behave
Please see answer from AlmasK89 below for running makemigrations in Django 1.9 or higher: https://mcmap.net/q/609149/-table-thumbnail_kvstore-doesn-39-t-existAthena
C
1

Use version 12.3 of sorl-thumbnail. Follow this steps

Remove actual version

pip uninstall sorl-thumbnail

Install version 12.3

pip install git+git://github.com/mariocesar/[email protected]

Migrations

python manage.py migrate
Casady answered 16/8, 2017 at 0:13 Comment(0)
D
0

For me the error just occurred while executing dumpdata.

So if you find this thread here because you tried to use dumpdata, then excluding the thumbnail app will probably be an easy workaround for you:

python manage.py dumpdata --exclude thumbnail

Of course you should follow the other answers, if you want to have your Django clean.

Dahlberg answered 10/8, 2017 at 16:12 Comment(1)
this one is useful for a quick test when you don't want to run migrations, etcOsullivan

© 2022 - 2024 — McMap. All rights reserved.