django template does not change after update or insert data MySQL - mysql

My website running with django, uwsgi & nginx. whenever I insert or update data to mysql, the new content that rendered to page supposed to be changed but it wasn't until I refresh the pages many times or restart the uwsgi, I'm new using django, I don't know if it has something to do with caches.
the question is how can I manage the cache at django to maintain the database access in order to direct any changes in the page without restarting the uwsgi. Thank you.

Try to apply migration.Applying migration will update your database and the try to run server or visit your website it will show you change.
If you're at Django1.8+
use this command for migration:
python manage.py makemigrations
and after that use migrate command:
python manage.py migrate
and then run your server or relode the webpage.
hope it solve your issue

Related

Flask migration error when using flask-migrate

I can't seem to get Flask to migrate my models. I'm following along with the Flask Mega-Tutorial series. At the database setup part of the tutorial, I'm just trying to substitute MySQL for SQLite that is used in the tutorial.
I followed SQLAlchemy's instructions for connecting to a MySQL database, and I've included mysqlclient in my pipfile.
But when I run:
flask db init
flask db migrate
I get the following:
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [root] Error: Can't locate revision identified by '7bb962b87f19'
I've tried deleting the migrations folder, and I've deleted the environment and recreated to see if that would fix anything. But it keeps saying it can't locate revision. I thought maybe it did something with the database, I've read other solutions saying you have to flush the database. But, there aren't any tables created or any schemas in the database.
Other info:
DATABASE_URL="mysql://root:mypassword#localhost/flask_tutorial"
SQLite database runs fine and makes the migrations. So it must be something I've done with the mysql setup.
Any suggestions or ideas that may lead me in the right direction would be greatly appreciated.
The session was storing incorrect environmental variables exported. Had to completely restart my machine for the settings to reset. I even tried unset for the variables, which didn't remove the variables. Once Flask was able to pick up the correct variable settings for my configuration everything worked as planned.
Please make sure you have used this "SQLALCHEMY_TRACK_MODIFICATIONS= True"
Did you install MySqldb lib. to connect with your mysql db ?
I had the same issue. I had deleted the migrations folder but hadn't done the same for the app.db file. So, every time I tried to create any db migrations, it failed because it was using the old (and still existing) app.db file.
This is how my database was configured:
class Config(object):
# Database configuration
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
'sqlite:///' + os.path.join(basedir, 'app.db')
SQLALCHEMY_TRACK_MODIFICATIONS = False
Deleting the app.db file solved the error. Subsequent db migrations and upgrades worked well.

How to connect to a mysql database from Django?

I have an inscription.sql on a WAMP localhost:80 server, and I have also Django running on visual studio via a localhost:xxxx server.
I want to connect Django to the mysql database located on the wamp server (I have successfully installed MysqlClient).
Is there anyway to do this?
See the official guide to using an already existant database with Django.
To sum up, what you need to do is:
Make sure Django can connect to your database by setting the right DATABASE setting. From your comment, this seems to be the case.
Generate models (Python code) that match the tables in your database using the python manage.py inspectdb command. You must paste the generated code in the models.py file of an installed app and review them to make sure they fit your needs.
Create the tables required by Django with the python manage.py migrate command.
From the docs
Jus set the DATABASES variable in settings, then run python manage.py inspectdb > models.py put the generated models.py in the app's folder and finally run python manage.py migrate

Django 1.8 migrations "Table already exists"

I've been working on making an auto-deployment system to make updating my django site easier, and it mostly works, but right now my database changes are screwy. I have the auto deployment run "makemigrations" "migrate" then "syncdb"
The trouble I have is when I run migrate, it tells me that my table already exists and can't be created. Previous answers have said to run "migrate --fake", but if I do this, it appears to think everything is up to date. The issue then is that I run "makemigrations" or "migrate" and it says no changes detected (even though there is a missing column from my database). I tried to run "sqlall" to figure out what it thinks the database should be, and it tells me that I have pending migrations. So I tried running "migrate" and it said no migrations exist.
How do I manage this? And in the future, what should I do for database migrations to troubleshoot/fix these problems?
Thanks
I fixed the problem. The issue stemmed from a misunderstanding of how Django migrations worked. Also, as per the comments, syncdb is no longer a command in manage.py.
The original issue was that I had been using a different database for deployment and then I switched and my migrations were out of sync from my development database, so I had to clear out both databases and migrations and start over with my data. Then I run makemigrations on my local machine and migrate there (for my dev DB). Then I upload to the server and have the fab script run migrate on the server production DB without calling makemigrations. This seems to have fixed the issue.

How do I make changes to a Django Model after it has been deployed to a webserver?

In development, whenever I make changes to the underlying model in my Django application, I'm used to:
Stopping the development server
In MySql, dropping the existing database
running $>python manage.py syncdb
Restarting the development server by running $>python manage.py runserver
Once deployed using WSGI & Apache, however, I don't have the development server running. As such, I don't know how to stop the server, and just running:
$>python manage.py syncdb
didn't appear to update the underlying MySql database that instantiates the model. So, short of tearing down the entire instance, how do I update my database?
Note: I implemented this before I learned about db migrations using "south" so I'm looking at raw Django, I suspect.
Django doesn't have a migration framework built-in (yet!), so there's no such thing as "raw django for migrations".
Consequently, you either do that manually (using SQL to alter the table), or you use south.
Now, my recommendation would be to use south.

Proper way to set two Rails applications on same server

I have two (same) applications running on dev.example.com and beta.example.com with different databases. Everything is set to run with passenger using Apache as web server.
What I have done was to copy the code from one directory to the other (myapp_dev and myapp_beta) and everything seems working fine, until I have to migrate a table. I get an error that the data I want to migrate is already migrated. Probably trying to migrate on the same database. Maybe I have to re-configure the way to run the applications, but don't know how and what to do. Any hints are appreciated.
Thanks!
you can change the used database in config/database.yml