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?

[Django] アプリをもう1つ作る (エラーがでて解決)

Posted at

前回の記事で作成したsample_appフォルダをコピーして、
sample_app2 を作成しました。
そこで、
python manage.py runserver
で立ち上げようとしてもエラーが出てうまくいきません。
こんなエラーメッセージが出ます。

django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: sample_app

エラーメッセージで検索して、色々調べていたら、

1つめの記事の方法

my_project\settings.pyの、
INSTALLED_APPS の部分で重複しているとエラーになるらしい、ということが書かれていたので、

修正して、下記のように、sample_app2.apps.SampleAppConfigを追加しました。

my_project\settings.pyのINSTALLED_APPS
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'sample_app.apps.SampleAppConfig', 
    'sample_app2.apps.SampleAppConfig', # Add
]

しかし、エラー解決せず。。。
sample_app.apps.SampleAppConfig と sample_app2.apps.SampleAppConfig で重複してないはず。。。

どうも、
まだ他の部分でどこか重複している模様です。

2つめの記事の方法

その後、この記事を見て、

sample_app2\apps.py
の、

sample_app2\apps.py
class SampleAppConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'sample_app'

この部分、

    name = 'sample_app'

これが、sample_app\apps.py と、同じ名前だとダメの模様。

    name = 'sample_app'

    name = 'sample_app2'

と変更し、
下記のようにしてみた。

sample_app2\apps.py
class SampleAppConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'sample_app2'

すると、エラーが出なくなりました。

0
0
0

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?