django app multiple hard drives [Errno 18] Invalid cross-device link
<p>I have a django app on a debian server and my current site_media directory on the current disk is full. So I want to upload files On a second disk. The path on server is /disk :</p>

<pre><code>        obj = form.save(commit=False)
        obj.user_id = self.request.user.pk
        obj.save()
        initial_path = obj.file.path
        print(initial_path)
        new = settings.MEDIA_ROOT_NEW + obj.file.name
        print(new)
        os.rename(initial_path,new)
        shutil.move(initial_path, new)
</code></pre>

<p>and in my settings.py I have:</p>

<pre><code>        MEDIA_ROOT = os.path.join(PROJECT_PATH, 'site_media/')
        MEDIA_ROOT_NEW = '/disk/site_media/'
</code></pre>

<p>still I get error:
django [Errno 18] Invalid cross-device link</p>

<p>Any ideas???</p>

<p><code>os.rename()</code> may fail across different file systems.</p>

<blockquote>
  <p>The operation may fail on some Unix flavors if src and dst are on different filesystems.
  <a href="https://docs.python.org/3/library/os.html#os.rename" rel="nofollow">https://docs.python.org/3/library/os.html#os.rename</a></p>
</blockquote>

<p><code>shutil.move()</code> should work</p>

<blockquote>
  <p>If the destination is on the current filesystem, then os.rename() is used. Otherwise, src is copied (using shutil.copy2()) to dst and then removed.
  <a href="https://docs.python.org/3.4/library/shutil.html#shutil.move" rel="nofollow">https://docs.python.org/3.4/library/shutil.html#shutil.move</a></p>
</blockquote>

<p>but you've got a <code>os.rename(initial_path,new)</code> just before your <code>shutil.move(initial_path, new)</code>. Remove the first <code>os.rename()</code> and it should work.</p>

python django server debian-based