0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

docker compose upしたときにAttributeError: module 'django.db.migrations' has no attribute...'××'のエラーが出た時の対処法

Last updated at Posted at 2025-04-10
AttributeError: module 'django.db.migrations' has no attribute '××'

Djangoで開発中このエラーが出た場合の対処法。
このエラーはdjango.db.migrations に ‘××’ という関数名、クラスがない、という意味でマイグレーションの状態が双方食い違っているときに起こる。

まずはコンテナ名を確認する。

docker ps

そしたらDockerの中に入る。

docker exec -it `コンテナ名` /bin/bash

そしたらmanage.pyがあるところから、showmigrationsして差分を確認する。

python manage.py showmigrations

結果はこちら

user
 [X] 0001_ファイル1
 [X] 0002_ファイル2
 [X] 0003_ファイル3
 [X] 0004_ファイル4
 [ ] 0005_××

××が対象のファイルである時に、userの中の××がまだ適用されていないことがわかる。

その場合はmigrateしてあげる。

python manage.py migrate

また下記の場合もある。

user
 [X] 0001_ファイル1
 [X] 0002_ファイル2
 [X] 0003_ファイル3
 [X] 0004_ファイル4
         .
         .
         .

そもそもこのように対象のファイルが見つからない場合は、makemigrationsをしてあげると良い。

 python manage.py makemigrations

これでもう一回docker compose upしたらエラーがとれてます。



以上です。

Djangoは会社で使う機会が多いのでまたわからなくなったらまとめます。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?