I have been working on an application using django and mysql, am trying now to work on the tutorial from this here
http://docs.djangoproject.com/en/1.2/ref/contrib/gis/tutorial/
but it failed the moment I ran syncdb with the following error
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
When I read around, it says that this can be solved if changed the backend to use postGIS. Is there a way to continue using mysql as my backend and yet be able to use geodjango? if not, is it possible to use both in the same project?
Regards,
set django.contrib.gis.db.backends.mysql in your settings.DATABASE engine db config.
Does your MySQL have spatial data types installed? What do you get if you do:
CREATE TABLE geom (g GEOMETRY);
If that doesn't recognise the GEOMETRY type, then you need to upgrade/recompile/reconfigure your MySQL.
Related
I am already having one mysql database with a lot of data, of which tables and migrations are written in sql. Now I want to use the same mysql database in django so that I can use the data in that database.I am expecting that there will not be need for making the migrations as I am not going to write the models in Django again, also what will be the changes/modification I will have to do. For eg: as in middlewares?. Can anyone please help me in this?
From what I know there is no 100 % automatic way to achieve that.
You can use the following command
python manage.py inspectdb
It will generate a list of unmanaged models that you can export to a model.py file and integrate in your django project.
However it is not magical and there are a lot of edge cases so the generated list of model should be manually inspected before being integrated.
More info here : https://docs.djangoproject.com/en/3.0/ref/django-admin/#django-admin-inspectdb
I'm not very familiar with Django (I've used more Flask, Web.py, and Falcon), and one thing that I'm finding strange is that when I look at the 'Database' tab in PyCharm, I don't see a list of all of the tables that seem to be getting used in the database:
If I use python manage.py dbshell to start a sqlite3 session and then type .tables, this is the list of tables that I see:
How do I get those tables to be browsable from within the PyCharm database viewer?
Posting the comment as an answer:
PyCharm is occasionally a little slow on the uptake for new tables.
The Refresh/Synchronize button on the Database panel usually fixes that.
I'm running a simple Flask app with Heroku, and I can run the following command to create all the tables:
db.create_all()
However, I ship new stuff frequently and I often need to add new columns to existing tables. Is there an easy way to do this?
If I need to manually create a new column with Postgres, how would I access the repl for Heroku's Postgres database?
You should be using migrations.
This is a great plugin for that: https://flask-migrate.readthedocs.io/en/latest/
and this is a good explanation about how to get going with that: https://realpython.com/flask-by-example-part-2-postgres-sqlalchemy-and-alembic/
I'm using this seed https://github.com/Pylons/pyramid_blogr
The seed uses sqlite, sqlalchemy and the pyramid frame work.
I have not modified the seed at all.
How do I print out my tables, from a shells?
Thank you for the help.
I am new to pyramid, and python, but I have done introduction work on node.js and django.
I used the sqlite3 command line with, 'sqlite3 gw.db' (gw is my app named), but i think this started a new db instance.
I am working on an Ubuntu 14.04 server with a mean stack installed.
To print sqlite tables via shell, use the sqlite3 command-line utility. It's not clear whether you want to print a list of tables, the database schema, or in what output format, but all of that is covered in the documentation.
How can I create one model that talks to two databases in Flask, where one is, say, sqlite, and the other is specifically neo4j?
I'd like to have login and password stuff in a traditional db, and keep other graphy information in neo4j. I'm told neo4j is bad for things that need large graph traversals. Perhaps I'm wrong in needing this, but I have an instance where I'd like to say something like...
"return a dict(person.x,person.y,person.z) from all nodes where type==person", and then feed that into the view of my index page.
I've seen related questions about ORMs with neo4j:
ORM with Graph-Databases like Neo4j in Python
...and this about multiple DBs in Flask:
http://packages.python.org/Flask-SQLAlchemy/binds.html
Specifically, I see this taking the form of my create statement writing to sqlite db connection and then writing a key from there to additional relational information in neo4j.
I've recently released an OGM (Object-Graph Mapping) module for py2neo (http://book.py2neo.org/en/latest/ogm.html). This might help with what you're trying to do.
Otherwise, you could also look at neomodel (https://github.com/robinedwards/neomodel). It's written for Django but should be usable in Flask too.
I don't know about mixed backend models, but I think depending on your user count, you can use neo4j for your users, too. If you put the user nodes into an index, you can get all users without searching the graph.
If you find that this actually is a bottleneck, migrating it to a split storage should not be too difficult.
It is not that hard to adapt neo4j-driver and py2neo to use eg. Flask-Login.
I have use py2neo to that and worked well, but migrated now to neo4j-driver
Downside is that i did not manage to get it working with eg SQLalchemy etc.
Using a double backend solution is not a problem, in an earlier project i have used SQLalchemy with SQLite3 and PostgreSQL, Neo4j and redis together.
Using that, i have found no issues other than some design issues.