djangoでアプリ制作をしようと
まずはmodelを作りmakemigrationsをしたいのですが
このエラーにずっと苦戦してます。。。
models.py
1from django.db import models 2from django.contrib.auth.models import User 3from datetime import datetime 4 5class Post(models.Model): 6 author = models.ForeignKey(User, on_delete=models.CASCADE) 7 photo = models.ImageField(upload_to='media/', blank=True, null=True) 8 caption = models.TextField(blank=True, null=True) 9 likes = models.ManyToManyField(User, related_name='liker',blank=True) 10 follow = models.ManyToManyField(User, related_name='follower') 11 published_date = models.DateTimeField(auto_now_add=True) 12 tag_name = models.CharField(max_length=10, blank=True, null=True) 13 14 def __str__(self): 15 return self.caption 16 17class Comments(models.Model): 18 comment = models.CharField(max_length=500) 19 commenter = models.ForeignKey(User, on_delete=models.CASCADE, 20 related_name='commenter') 21 posted_id = models.ForeignKey(Post, on_delete=models.CASCADE) 22 pub_date = models.DateTimeField(auto_now_add=True) 23 24 def __str__(self): 25 return self.commenter 26 27 28class Favorites(models.Model): 29 post = models.ForeignKey(Post, on_delete=models.CASCADE, \ 30 related_name='favorite_post') 31 favorite_ppl = models.ForeignKey(User, on_delete=models.CASCADE,) 32 33 34 35class Follow(models.Model): 36 follower = models.ForeignKey(User, on_delete=models.CASCADE) 37 38 39class Tags(models.Model): 40 tag_name = models.ManyToManyField(Post) 41
admin.py
1 2from django.contrib import admin 3from Sns.models import Post, Comments, Favorites 4 5# Register your models here. 6 7admin.site.register(Post) 8admin.site.register(Comments) 9admin.site.register(Favorites) 10 11
model,adminはこんな感じです。
File "manage.py", line 22, in <module> main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "/Users/rs0325/django/django/core/management/__init__.py", line 401, in execute_from_command_line utility.execute() File "/Users/rs0325/django/django/core/management/__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/rs0325/django/django/core/management/base.py", line 330, in run_from_argv self.execute(*args, **cmd_options) File "/Users/rs0325/django/django/core/management/base.py", line 371, in execute output = self.handle(*args, **options) File "/Users/rs0325/django/django/core/management/base.py", line 85, in wrapped res = handle_func(*args, **kwargs) File "/Users/rs0325/django/django/core/management/commands/makemigrations.py", line 164, in handle changes = autodetector.changes( File "/Users/rs0325/django/django/db/migrations/autodetector.py", line 43, in changes changes = self._detect_changes(convert_apps, graph) File "/Users/rs0325/django/django/db/migrations/autodetector.py", line 129, in _detect_changes self.new_apps = self.to_state.apps File "/Users/rs0325/django/django/utils/functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/Users/rs0325/django/django/db/migrations/state.py", line 208, in apps return StateApps(self.real_apps, self.models) File "/Users/rs0325/django/django/db/migrations/state.py", line 278, in __init__ raise ValueError("\n".join(error.msg for error in errors)) ValueError: The field Sns.Comments.posted_id was declared with a lazy reference to 'sns.post', but app 'sns' isn't installed. The field Sns.Favorites.post was declared with a lazy reference to 'sns.post', but app 'sns' isn't installed.
snsがインストールされていないということ?
ですがsetting.pyのinstalled_appの方にしっかり登録してあります。
setting.py
1INSTALLED_APPS = [ 2 'django.contrib.admin', 3 'django.contrib.auth', 4 'django.contrib.contenttypes', 5 'django.contrib.sessions', 6 'django.contrib.messages', 7 'django.contrib.staticfiles', 8 'django.contrib.sites', 9 10 'rest_framework', 11 'rest_framework.authtoken', 12 13 'Sns', 14
どなたか分かる方いましたら教えていただきたいです。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/07/07 10:45