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.
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 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.
I'm working on a project that I inherited, and I want to add a table to my database that is very similar to one that already exists. Basically, we have a table to log users for our website, and I want to create a second table to specifically log users that our site fails to do a task for.
Since I didn't write the site myself, and am pretty new to both SQL and Django, I'm a little paranoid about running a migration (we have a lot of really sensitive data that I'm paranoid about wiping).
Instead of having a django migration create the table itself, can I create the second table in MySQL, and the corresponding model in Django, and then have this model "recognize" the SQL table? without explicitly using a migration?
SHORT ANSWER: Yes.
MEDIUM ANSWER: Yes. But you will have to figure out how Django would have created the table, and do it by hand. That's not terribly hard.
Django may also spit out some warnings on startup about migrations being needed...but those are warnings, and if the app works, then you're OK.
LONG ANSWER: Yes. But for the sake of your sanity and sleep quality, get a completely separate development environment and test your backups. (But you knew that already.)
I'm working on a small project, and I wanted to provide multiple caching options to the end user. I figured with Django it's pretty simplistic to swap memcached for database or file based caching. My memcached implementation works like a champ without any issues. I placed time stamps on my pages, and curl consistently shows the older timestamps in locations where I want caching to work properly. However, when I switch over to the database caching, I don't get any entries in the database, and caching blatantly doesn't work.
From what I see in the documentation all that should be necessary is to change the backend from:
CACHE_BACKEND = 'memcached://localhost:11211'
To:
CACHE_BACKEND = 'db://cache_table'
The table exists after running the required manage.py (createcachetable) line, and I can view it just fine. I'm currently in testing, so I am using sqlite3, but that shouldn't matter as far as I can tell. I can confirm that the table is completely empty, and hasn't been written to at any point. Also, as I stated previously, my timestamps are 'wrong' as well, giving me more evidence that something isn't quite right.
Any thoughts? I'm using sqlite3, Django 1.0.2, python 2.6, serving via Apache currently on an Ubuntu Jaunty machine. I'm sure I'm just glossing over something simple. Thanks for any help provided.
According to the documentation you're supposed to create the table not by using syncdb but with the following:
python manage.py createcachetable cache_table
If you haven't done that, try and see if it doesn't work.