多対多リレーションシップにフィールドを追加したいと思って、Contactという中間モデルを作成しました。ユーザーが他のユーザーに従うことができ、その後も従うことができるシステム)。Django 1.10パスがマウント 'C:'、マウント 'D:'から開始
class Contact(models.Model):
user_from = models.ForeignKey(User,
related_name='rel_from_set')
user_to = models.ForeignKey(User,
related_name='rel_to_set')
created = models.DateTimeField(auto_now_add=True,
db_index=True)
class Meta:
ordering = ('-created',)
def __str__(self):
return '{} follows {}'.format(self.user_from, self.user_to)
私はDjangoが提供するUserモデル(django.contrib.auth.models)を使用しています。このモデルはフィールドを追加したいのであれば作成したものではないので、私は(少なくとも、猿のパッチを使って)それらをdinamically追加する必要があります。だから、models.pyファイルの最後に、私は次のコードを追加:
User.add_to_class('following', models.ManyToManyField('self', through=Contact , related_name='followers', symmetrical=False))
をしかし、私は次のエラーましpython manage.py makemigrations
runned:
Migrations for 'auth':
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\core\managem
ent\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\core\managem
ent\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\core\managem
ent\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\core\managem
ent\base.py", line 345, in execute
output = self.handle(*args, **options)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\core\managem
ent\commands\makemigrations.py", line 192, in handle
self.write_migration_files(changes)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\core\managem
ent\commands\makemigrations.py", line 210, in write_migration_files
migration_string = os.path.relpath(writer.path)
File "C:\Program Files (x86)\Python35-32\lib\ntpath.py", line 574, in relpath
path_drive, start_drive))
ValueError: path is on mount 'C:', start on mount 'D:'
を
"os.relpathは、2つのディレクトリ間の相対パスを提供します。
問題が発生した場合、Windowsでは相対パスが存在しない2つのディレクトリが異なるドライブ上にあります(エラーメッセージが示すとおりです)。 「
しかし、解決策は、私は、Windows 8とDjango 1.10を使用しています? ものです。
エラーは、追加されたフィールドと何か関係があると思いますか?いずれの場合でも、完全なトレースバックを表示する必要があります。 –
@DanielRoseman完全なトレースバックを掲載しました。上記のコードを追加した直後にエラーが発生したので、問題がどこにあるのかが肯定的です。 – ROBlackSnail