Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8829045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:44:42+00:00 2026-06-14T07:44:42+00:00

I have the following scheme for my project’s settings: myproject/ app1/ app2/ appN/ settings/

  • 0

I have the following scheme for my project’s settings:

myproject/
   app1/
   app2/
   appN/
   settings/
      __init__.py
      base.py
      devel.py
      production.py

In my local environment I have inside the virtualenvwrapper’s postactivate script:

myproject_root=/home/rantanplan/Projects/repos/myproject
cd $myproject_root
export DJANGO_SETTINGS_MODULE=myproject.settings.devel

So that when I do workon myproject it will change to the project’s root dir and
set the active DJANGO_SETTINGS_MODULE I want.

This is fine for django and all the commands(like python manage.py syncdb) work.

Now on the other hand I have this fabric task:

@task
def syncdb():
    local('python manage.py syncdb --noinput')

This used to work fine when I had a simple settings.py file, but when I changed
to the above scheme it raises this exception:

django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

Fatal error: local() encountered an error (return code 1) while executing 'python manage.py syncdb --noinput'

Aborting.

Some additional notes:

  • project function is not applicable here since it falsely assumes(internally) that all django settings modules are named as “settings”.
  • I tried the settings_module function to no avail. It uses os.environ internally to set the environment variable but to no effect.
  • If I print the os.environ['DJANGO_SETTINGS_MODULE'] just before my task definition, it correctly prints “myproject.settings.devel”.

So what am I doing wrong here and how do you propose I should go about solving this issue?


To spare you the trouble I should say that I know I can solve this by doing:

def syncdb():
    with prefix('export DJANGO_SETTINGS_MODULE=myproject.settings.devel'):
        local('python manage.py syncdb --noinput')

but I’d rather avoid the use of prefix if I can.

Also I know I could do, as hynekcer suggests:

@task
def syncdb():
    local('python manage.py syncdb --settings=myproject.settings.devel --noinput')

but I really want to know why local does not respect the DJANGO_SETTINGS_MODULE and
why settings_module does not work as advertised.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:44:43+00:00Added an answer on June 14, 2026 at 7:44 am

    Well I found the problem but I’m not sure what to make of it.

    First of all it seems that I didn’t reveal all the necessary bits of information.

    Although my django project’s structure is exactly as I described, my fabric
    structure is a bit more complex.

    In essence I follow some patterns from this part of fabric’s documentation

    The complete structure is described below:

    deployment/
      __init__.py
      fabric/
        __init__.py
        database.py
        repo.py
        services.py
    myproject/
      app1/
      app2/
      appN/
    manage.py
    fabfile.py
    

    Inside the deployment/fabric/database.py I had this code:

    django.settings_module('myproject.settings.devel')
    
    @task
    def syncdb():
        local('python manage.py syncdb --noinput')
    

    And inside my fabfile.py I had all my imports:

    from deployment.fabric.database import dropdb, createdb, syncdb, createuser
    from deployment.fabric.something import blahblah
    

    For some reason, that I can’t seem to grasp right now, inside the fabfile.py
    the setting of the DJANGO_SETTINGS_MODULE(which was happening inside the deployment/fabric/database.py) is not retained.

    At first I came to the false realization that os.environ actions do not persist
    across modules! But this is not true, as I immediately constructed a similar scenario
    outside my django project and invalidated my false premise.

    Then I checked fabric’s local function and saw that it essentially is a wrapper
    over subprocess.Popen('...', shell=True). So I tested my previous experiment
    with subprocess.Popen and it still retained the environment variables across modules.

    I don’t know if it has to do with fabric’s magic tasks import or there is something
    fundamental I don’t grasp but any of the below methods will solve the issue.

    1) Use the prefix context manager

    def syncdb():
        with prefix('export DJANGO_SETTINGS_MODULE=myproject.settings.devel'):
            local('python manage.py syncdb --noinput')
    

    2) Append a --settings value in the local command (as described by hynekcer)

    @task
    def syncdb():
        local('python manage.py syncdb --settings=myproject.settings.devel --noinput')
    

    3) Include the settings_module call inside the task(Although it kinda invalidates its purpose).

    @task
    def syncdb():
        django.settings_module('myproject.settings.devel')
        local('python manage.py syncdb --noinput')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a maven project with the following structure: spring-di-test +--spring-di-test-core | com.example.core.DITestMain +--spring-di-test-store
On a project, I have the following problem : I have a very simple
I have nested model as following Project model has_many keywords and keyword belongs_to project
I have the following data scheme that I want to turn into an application.
Suppose we have the following (Visual Studio) projects (simplified): base-lib-1 base-lib-2 product-1 : depending
I have the following :has_many :through relation. Associations class Profile < ActiveRecord::Base has_many :teams
Currently, we're using the following version numbering scheme for our C# winforms project: Major
I have done the following so far: Created workspace Added my project Added the
I have the following schema, which I use to ensure that a person's PhoneNumber
Suppose I have the following schema t = {name: 'John', reviews: [{sid: 1, comment:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.