0

So I built a postgres models.py and tried to create the below test data, all of which worked with sqlite.

basedir = os.getcwd()

app = Flask(__name__)

#...omitted for brevity

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

app.config['ENV_DB_CONNECTION_DSN'] = 'postgres:///Ocean.db'

db = SQLAlchemy(app)

db.create_all()

#testing starts below this

camelot = Entity(level='Province', name='Camelot',iso_code='CAM')

db.session.add(camelot)

lit = Literal_data(ent_id=1, year=2012, value=2, display_name = 'swallow count', meta_id=1)

db.session.add(lit)

swallow = Meta_indicator_data(p_name = 'swallow count',family = 'animal life',num_type = 'interger',provider = 'camelot bird comission',p_description = 'swallows. duh.')

db.session.add(swallow)

db.session.commit()

the above works fine, i can even query the db with db.engine.execute('select * from ent')

Only problem is I cant find the db file anywhere, including psgadmin III!

any ideas on how to print the db file name? can the above run with no errors without a db file??

6
  • Is it perhaps at the root of your filesystem, i.e. /? Commented May 30, 2016 at 19:14
  • Good thinking, but no Commented May 30, 2016 at 19:17
  • Possible duplicate of Where does PostgreSQL store the database? Commented May 30, 2016 at 20:03
  • I don't think so, I can see a directory with a bunch folders named for OIDs, but I cant tell what they correspond to. I have added and deleted test datbases before. Is there a way to read OIDs? Commented May 30, 2016 at 22:12
  • So apparently when I am commiting the data, the engine redefaults to sql lite >>> db <SQLAlchemy engine='sqlite://'> help?? Commented May 30, 2016 at 23:34

1 Answer 1

1

Basically my config just sucked I think, been a while since I was dealing with this. the current code reads

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
try:
    app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
except KeyError:
    raise Exception('I dont see a database connection in the Database URL system variablbe - see the read me on setting this up')

Where:

database_url = postgresql://$user:$password@localhost:5432/$databasename
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Saurav! looks much better

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.