[PYTHON] How to reflect ImageField in Django + Docker (pillow)

Introduction

In this article, I would like to write about the error that I actually suffered when reflecting "Image Field" through a solution.

kadaikun.Image.image: (fields.E210) Cannot use ImageField because Pillow is not installed.HINT: Get Pillow at https://pypi.org/project/Pillow/ or run command "pip install Pillow" At first I was plagued by this error. I installed pillow, but I was told that it was not installed and it was in a "?" State. For the time being, I tried to deal with it with the following command.

terminal


$ python3 -m pip uninstall pillow

$ python3 -m pip install pillow

And my great.

terminal


$ python manage.py migrate

result...

terminal


kadaikun.Image.image: (fields.E210) Cannot use ImageField because Pillow is not installed.
        HINT: Get Pillow at https://pypi.org/project/Pillow/ or run command "pip install Pillow"

It was bad....

At this time, I realized that I was using Docker ...

This was my first time using Docker, so I only knew if I should change the "Dockerfile" or "requirementes.txt".

For that reason, I wrote everything that came out googled into the Dockerfile from one end and repeated "docker-compose up" all the time.

/bin/sh: 1: apk: not found

The result of repeating ...

terminal


/bin/sh: 1: apk: not found

I just got an error and it didn't solve at all.

Meanwhile, I finally found an article that seems to be solved.

That is this article. A place stuck with Docker + django

In a Dockerfile like this article

Dockerfile


RUN pip install pillow

In "equirementes.txt",

equirementes.txt:equirementes.txt


Pillow==7.2.0

Enter.

Then type in the terminal as follows:

terminal


$ python manage.py makemigrations

$ python manage.py migrate

$ docker-compose up

That's it! I'd like to say, but I got an error when I opened the browser ...

OperationalError Despite the error, this solution was easy.

terminal


$ rm -d -r db.sqlite3
$ rm -d -r app/migrations/*
$ python manage.py migrate

This is OK!

Finally

terminal


$ docker-compose up

If you type in, it should be reflected beautifully.

By the way, here is the article I referred to.

django.db.utils.OperationalError: no such column: app_action.author_id error when opening web page ](https://teratail.com/questions/87239)

Finally

This time I wrote about the error I experienced. I will post an article about Djnago in the future, so I hope it will be helpful.

Recommended Posts

How to reflect ImageField in Django + Docker (pillow)
How to reflect CSS in Django
How to log in to Docker + NGINX
How to delete expired sessions in Django
How to do Server-Sent Events in Django
How to convert DateTimeField format in Django
How to run some script regularly in Django
How to create a Rest Api in Django
How to get multiple model objects randomly in Django
How to build a Django (python) environment on docker
How to use bootstrap in Django generic class view
How to upload files in Django generic class view
How to use Decorator in Django and how to make it
How to reference static files in a Django project
How to develop in Python
How to write custom validations in the Django REST Framework
How to use Laravel-like ORM / query builder Orator in Django
How to check ORM behavior in one file with django
How to update user information when logging in to Django RemoteUserMiddleware
[Django] How to give input values in advance with ModelForm
How to generate a query using the IN operator in Django
How to implement Python EXE for Windows in Docker container
In Django, how to abbreviate the long displayed string as ....
[Python] How to do PCA in Python
How to handle session in SQLAlchemy
[Django] How to test Form [TDD]
How to use classes in Theano
How to write soberly in pandas
How to collect images in Python
Errors related to memcached in django
How to update Spyder in Anaconda
How to use SQLite in Python
How to convert 0.5 to 1056964608 in one shot
How to get started with Django
How to kill processes in bulk
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
How to use PubChem in Python
How to delete a Docker container
How to write Docker base image
How to write Django1.9 environment-independent wsgi.py
How to run TensorFlow 1.0 code in 2.0
How to handle Japanese in Python
How to authenticate with Django Part 2
How to authenticate with Django Part 3
How to call PyTorch in Julia
How to debug Dash (Flask) in Docker + VSCode + remote connection environment
[Django] How to read variables / constants defined in an external file
I want to create a pipfile and reflect it in docker
How to deploy a Django app on heroku in just 5 minutes
Learn how to use Docker through building a Django + MySQL environment
How to do arithmetic with Django template
[Introduction to Python] How to use class in Python?
How to suppress display error in matplotlib
Django: Migration doesn't reflect model in DB
How to access environment variables in Python
How to dynamically define variables in Python
How to check the version of Django
How to convert csv to tsv in CLI
How to create an NVIDIA Docker environment