title: Environmental variables from .env file not available during local migrations in django, heroku
body: <p>I have been developing on Heroku, using the <code>config</code> variables to store sensitive and other environmental variables.  While developing locally, I have mirrored these variables in the <code>.env</code> file.  </p>
  
  <p>What I am finding now is the variables from the <code>.env</code> file do not load during migrations.  They ARE loading while running the local web server with <code>heroku local</code>, but NOT loading for migrations.  This was not a problem while my local app was still using the default sqlite3 database, because the sqlite default DB was "hard-coded" in the settings file.  However recently I want to use my local Postgresql DB for local dev. OK so I added the <code>DATABASE_URL</code> variable to my <code>.env</code> file.  </p>
  
  <p>I cannot get my local app to migrate to the DB.  I have found out that this is because the <code>.env</code> file contents are not added to the <code>os.environ</code> mapping duing migrations.</p>
  
  <p>To test, I added a test variable to the <code>.env</code> file:</p>
  
  <pre><code>TEST="teeeest"
  </code></pre>
  
  <p>Then in <code>settings.py</code>:</p>
  
  <pre><code>import os
  import dj_database_url
  
  if "TEST" not in os.environ:
      raise Exception("No .env vars found.")
  </code></pre>
  
  <p>I tried <code>python manage.py migrate</code>:</p>
  
  <blockquote>
    <p>File "/Users/apple/heroku/b/b/settings.py", line 16, in 
        raise Exception("No .env vars found.") Exception: No .env vars found.</p>
  </blockquote>
  
  <p>However I can run <code>heroku local</code> and there is no error.  I have also done further testing to ensure that the <code>.env</code> variables ARE available during <code>heroku local</code>.</p>
  
  <p>For various reason I want to set my local DB connection string in the <code>.env</code> file, but doesn't seem possible at the moment.  Is this the correct behavior for django on heroku?  <code>.env</code> file variables are only accessible when you run the server, and not for migrations?</p>