Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

manage.py syncdb is using another project's db in the virtualenv

I have 2 sites, in the same virtual env, in 2 different apache VirtualHosts.

When I run python manage.py syncdb, it says:

Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

When I run python manage.py inspectdb > somefile.txt, details of the other site appear in somefile.txt.

So python manage.py is calling the file /var/www/venv/proj1/manage.py even when I'm sitting in the directory of: ``/var/www/venv/proj2/`. Any reason what would cause this or how to diagnose this?

manage.py:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proj1.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

And this is how I checked $PYTHONPATH:

# $PYTHONPATH
-bash: /var/www/virtualenv-2.7/proj1:/var/www/virtualenv-2.7/proj2:: No such file or directory

And this is .bash_profile:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH


PYTHONPATH=/var/www/virtualenv-2.7/proj2:$PYTHONPATH
PYTHONPATH=/var/www/virtualenv-2.7/proj1:$PYTHONPATH
export PYTHONPATH

export DJANGO_SETTINGS_MODULE="proj2.settings" #possibly the issue?
like image 546
User Avatar asked Mar 03 '26 01:03

User


1 Answers

Your problem is that your PYTHONPATH has proj1 listed before proj2. In that case, python will first look into proj1 for manage.py and execute that, and skip the manage.py in the current directory, even if it exists.

As a quick fix, add the current directory to the PYTHONPATH like this:

PYTHONPATH=/var/www/virtualenv-2.7/proj2
PYTHONPATH=/var/www/virtualenv-2.7/proj1:$PYTHONPATH
PYTHONPATH=.:$PYTHONPATH
export PYTHONPATH

This will first check for the script you're looking for in the current directory.

Also, unless you have a specific goal in mind, you can lose the project specific paths and always start manage.py from the relevant directory.

like image 109
Andrei Avram Avatar answered Mar 05 '26 17:03

Andrei Avram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!