당연히 데이터베이스를 직접 수정하여이 작업을 수행 할 수 있습니다. 당신은 장고 기반의 스크립트를 사용하여 실행하는 SQL 코드를 만든 다음 (내 경우 sqlite3를에) 데이터베이스를 통해 실행할 수 있습니다
# Set up django environment
from django.core.management import setup_environ
from app import settings
setup_environ(settings)
from project.app.models import MyModel
# Prints sql to update file locations since django won't :(
for myModel in MyModel.objects.all():
# You can do the below even better if you use the same method as the model uses
# to generate upload_to
file_name = 'my_file_this_should_depend_on_myModel'
file_location = 'path/to/file/dir/%s' % file_name
print "UPDATE app_mymodel SET file_field='%s' WHERE id=%s;" % \
(file_location, myModel.id)
그런 다음이 스크립트의 출력을 사용하여 DB를 통해 실행!
티켓은 질문과 관련이 없습니다. 티켓은 DB 내부의 BLOB에 파일을 업로드하는 것이지만 질문은 업로드하는 대신 파일 시스템의 기존 파일을 가리 키도록 파일 필드를 변경하는 것입니다. . –