How to solve operationError: no such table - python

I'm setting up my new website, but the web have some problem. It gives me an OperationalError at /topics/ and no such table: toms_topic.
This is a Heroku web dyno, running Django2.2 and Python 3.7.3.
I have executed
python manage.py migrate
and when I go to the db.sqlite I find the table toms_topic exists.
And everybody can goto the website https://cblingh.herokuapp.com for take more information
My last website haven't this problem,maybe I add image this time,and the image is foreignkey with topic.But i not sure it's the key of this problem yet.The topic have two foreignkey (entry,image).

You can't use SQLite on Heroku. Its filesystem is dyno-local and ephemeral. Any changes you make to it will be lost whenever your dyno restarts. This happens frequently (at least once per day).
Heroku offers good support for client-server databases. If you want to use Heroku you'll have to switch to one. Their own PostgreSQL service works well and is available out of the box. If you prefer other databases feel free to browse the data store addons.

Related

How to use database in Heroku

I am new in web applications and I created first application in django. I decided to deployment my project in Heroku. But I'm so confused about database. I click "Heroku pricing" and I see 4-5 options. Free, Hobby, Standart, etc. And then i see databases options except these options. What is this?? as I said, this is my first applications and I dont know much about web servers. but as far as I know, service providers offer certain packages. These packages include RAM, Storage, Traffic, Database, ... etc.
In short, my questions are:
Is database included in heroku pricing?
I saw "connection 0 of 20" while using the heroku database. Does this mean only 20 users can access the site?
When I browsed the Heroku site, I didn't see any storage information in the pricing section. no storage pricing on cloud-based deployments?
Can I create a different database outside of the heroku environment and connect it to heroku?
every answer given informs and improving me. Thank you
Heroku PostgreSQL Hobby Dev pack is free
Go to Heroku dashboard
After creating an app, click on it
Go to Resources
Under Add-ons, in search bar type postgresql
Click on Heroku postgres
In plan name select Hobby Dev Free
Then Click on Heroku Postgres and get your credentials

What GIT / workflow do I use to avoid overwriting my server side Django users, with my local users who are dummy/test users?

I am developing a Django application in Atom locally, and then on pythonanywhere, when I'm ready, I'm doing a GIT PUSH command after syncing those changes to GITHUB. The problem is, at some point, those changes which were pushed through from my local development env have overwritten all my live users with just the local dummy users I've been using for testing and development.
Basically, I'm testing the login and registration system locally, logging in and registering with lots of dumb emails. Once I was happy it was working, I synced the Django code I'd changed to GITHUB (with the desktop app) and then did a GIT PUSH command on a PythonAnywhere (my server) console. The sqlite DB is included in those updates/sync - is that correct? Or should it just be totally ignored?
I just realised, that one (perhaps all?) pushes have overwritten my sqlite DB, and there were perhaps 30 or so actual users who had signed up on the website whose data is no longer registered on the site. I managed to find a trace of them in the Django Admin logs, and I've found the version history of the Sqlite DB on GITHUB, but my question is - how do I avoid this happening?
What is the workflow to avoid this situation in the future? And is there a command I can run in shell to get those users back into my 'live' database from the backedup SQlite file?
I know this is a simple question, but I'm new to development and I'm slowly getting there with troubleshooting the code, but versioning, GIT, and workflow are tricky things to get my head around.

Django app on Heroku deletes objects after some time

I've written a simple Django Q&A forum app and deployed it on Heroku. The local version of the site works fine. However, the production version does not store the questions, answers etc. for more than a few hours.
I decided to stick with sqlite3 that comes with Django. I don't expect a lot of traffic to the site so I decided it would be worth it to keep the development database for now.
site: http://immense-plateau-35286.herokuapp.com
I've tried a few solutions from the DB setup page on Heroku, but have not had any success so far.
Any idea what this might be?
Heroku's filesystem is ephemeral. Anything you write to it will be lost anytime your dyno restarts, which happens frequently. Since SQLite stores its data in a file on the filesystem it isn't a good choice on Heroku.
Instead, consider using one of the many client-server data stores that Heroku supports. Its PostgreSQL offering works reasonably well.

using mysql instead of sqlite3

im working on python application that requiring database connections..I had developed my application with sqlite3 but it start showing the error(the database is locked).. so I decided to use MySQL database instead.. and it is pretty good with no error..
the only one problem is that I need to ask every user using my application to install MySQL server on his pc (appserv for example) ..
so can I make mysql to be like sqlite3 apart of python lib. so I can produce a python script can be converted into exe file by the tool pyInstaller.exe and no need to install mysql server by users???
update:
after reviewing the code I found opened connection not closed correctly and work fine with sqllite3 ..thank you every body
It depends (more "depends" in the answer).
If you need to share the data between the users of your application - you need a mysql database server somewhere setup, your application would need to have an access to it. And, the performance can really depend on the network - depends on how heavily would the application use the database. The application itself would only need to know how to "speak" with the database server - python mysql driver, like MySQLdb or pymysql.
If you don't need to share the data between users - then sqlite may be an option. Or may be not - depends on what do you want to store there, what for and what do you need to do with the data.
So, more questions than answers, probably it was more suitable for a comment. At least, think about what I've said.
Also see:
https://stackoverflow.com/questions/1009438/which-database-should-i-use-for-my-desktop-application
Python Desktop Application Database
Python Framework for Desktop Database Application
Hope that helps.
If your application is a stand-alone system such that each user maintains their own private database then you have no alternative to install MySQL on each system that is running the application. You cannot bundle MySQL into your application such that it does not require a separate installation.
There is an embedded version of MySQL that you can build into your application (thanks, Carsten, in the comments, for pointing this out). More information is here: http://mysql-python.blogspot.com/. It may take some effort to get this working (on Windows you apparently need to build it from source code) and will take some more work to get it packaged up when you generate your executable, but this might be a MySQL solution for you.
I've just finished updating a web application using SQLite which had begun reporting Database is locked errors as the usage scaled up. By rewriting the database code with care I was able to produce a system that can handle moderate to heavy usage (in the context of a 15 person company) reliably still using SQLite -- you have to be careful to keep your connections around for the minimum time necessary and always call .close() on them. If your application is really single-user you should have no problem supporting it using SQLite -- and that's doubly true if it's single-threaded.

Django project using wrong (old) database settings

recently I started a small Django project that I developed on a local machine using a SQLite3 database and the integrated development server. I now copied the whole project to a server running Debian.
Everything worked well as long as I kept using the SQLite3 database. Now I wanted to switch to a local MySQL database, so I changed the settings.py file in my project's root folder, created the database and added a user. I then ran syncdb and it created the needed tables without any problems.
Now I wanted to use the app, but I keep getting errors, because Django can not find the tables - neither the 'standard tables' like django_sessions nor my own tables - even though they are there (I checked the database).
The one thing that seems awkward about the DatabaseError pages I get is the following line:
Exception Location: /usr/local/lib/python2.6/dist-packages/django/db/backends/sqlite3/base.py in execute, line 234
It seems like Django is still using the SQLite3 backend even though I set it to use the MySQL backend.
The other thing that nearly makes me freak out is this: I deleted the data.sqlite file in my app's root folder using rm. But when I use my app, the file is being recreated!
Can anyone tell me where I went wrong?
When running in production with mod_wsgi or mod_python, new code isn't incorporated until you reload/restart the webserver.
If you are using apache with mod_wsgi, you can also touch the wsgi.py file to restart the python code only.
If running on apache run "sudo /etc/init.d/apache2 reload" everytime you make a change.

Categories

Resources