Why is my Django object deleted with no reason? - django

I know this question may not be in appropriate shape, but I have no other way to describe it.
I have a Django project, deployed with Heroku. I'm using Postgres add-on. The problem is, few of the objects that my users created is being deleted for some reason. I tried to see if there's a pattern with this issue, but I haven't found one. It happens randomly. (This usually happens when I share(copy+paste) a user's post to other people, but I'm not sure if it's a pattern.)
I know it's not the heroku ephemeral filesystem issue, because I'm using the Postgres add-on. So I started wondering if there could be something wrong with Heroku or the Postgres add-on itself. This is a quite serious issue, but I can't figure out what the problem is.
Has anyone experienced similar issue or knows the answer to this?
Thank you very much.UpdateSo I've checked my settings.py, and I have this :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME' : str(BASE_DIR / 'db.sqlite3'),
}
}
...
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
However, I'm using Postgres add-on in my Heroku..

Related

Data always resets to original state on heroku free account after some time

I have deployed my django app into heroku free account.(first time)
In my working environment I use SQLLite on Heroku I assume POstgres should work.
However I am confused whats going on.
So first of all the app is up and running the data that was in my SQLlite database is currently shows at my deployed app.
Is it because my SQLLite DB was copied to heroku and this is what I actually see?
Another issue that indicates somthing is wron with DB is that if I create superuser via terminal I cant log with it to my app.
Another issue is that it looks data constantly restores to its original state after some time .
I followed the instructions and this is what I have in my settings for DB
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
import dj_database_url
db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)
Because that is how Heroku works. The file system is ephemeral and you must not store anything on it; but sqlite does store is data there, so it will get reset every time a new dyno is started.
Your reference to postgres is confusing. You are not using postgres, but you must.

Django unable to open database file using mysql

I'm a newbie in django so as python
I just succesfully configured my first django site over an apache server, then I configured it to work with mysql database editing the settings.py file and running the following command
python manage.py syncdb
I started playing a bit with the admin but occasionally when making get or post requests I get the following message OperationalError at "/some/route" unable to open database file
If I refresh the page loads fine, but if i keep refreshing any page in the admin the error shows up, so it's a random thing.
For what I've searched this is an issue related with sqlite, but I'm using mysql.
My database config in settings.py is the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'simulation',
'USER': 'root',
'PASSWORD': 'root',
'HOST': ''
}
}
I tried to specify hosts "localhost" and "127.0.0.1" but the result was the same.
It's really important for me find a solution that uses mysql as database engine.
Any help would be really appreciated! Thanks.
I've encountered a similar problem that you have right here, in my instance it seemed like my settings.py file was cached on the server. Once I deleted the .pyc files it started working fine.
Also, what happens if you change your database to sqlite? It might be worth checking that your mysql database isn't playing up instead of django.
I ran into the same problem with Django/Mysql/WSGI/Apache setup. Similar to Serakiel, I think that the problem stemmed from server caching. Restarting apache fixed the problem for me.

Getting DatabaseError, no such table with sqlite3

First time deploying a project. Getting DatabaseError when navigating to a view that modifies or creates Objects in the db. The error I get is:
DatabaseError at /uap_app/coach/request/
no such table: uap_app_coachrequest
with Traceback found here:
Suggestions include ensuring that settings.py reflects the full path for the db, which I have already done. Additionally, I have checked and ensured that all of the tables have been properly created by querying within the sqlite env. Tables initially created via manage.py sql uap_app and syncdb
in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '/var/www/cscc/uap_prod_db2.sqlite3',
Please let me know if there is anything else I should add?
Setup: Django1.4, Python2.7, Apache2.2, mod_wsgi, sqlite3, CentOS
Got it! My machine had multiple python versions installed so I needed to ensure that it pointed to the python2.7 executable instead of the default system-wide installed python.
added this line to httpd.conf:
WSGIPythonExecutable \usr\local\bin\python2.7
got an error from apache saying Invalid command 'WSGIPythonExecutable'-- apparently used only for a previous version of mod_wsgi 1.x (as per this post)
so then i tried adding this line to httpd.conf:
WSGIPythonExecutable \usr\local
and voila! It worked!
Thanks to unsorted for additional help

Setting up Websolr with Django on Heroku

I'm trying to add WebSolr support to my django powered app on Heroku. They have detailed instructions for an implementation using Ruby:
https://devcenter.heroku.com/articles/websolr
But I can't figure out how to tie it up to Haystack. Has any one done this?
Thanks.
Edit:
I was able to implement by modifying my settings.py file as:
HAYSTACK_URL = os.environ.get('WEBSOLR_URL', '')
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': HAYSTACK_URL,
},
}
Then running:
heroku run myproject/manage.py build_solr_schema > schema.xml
And uploading the contents of schema.xml to the advanced tab of the websolr interface. And once I ran
heroku run myproject/manage.py rebuild_index
the index was built.
I've updated the Heroku Websolr Docs to include a section on Django, based on your question. Thanks for that. For suggestions on our docs, drop a comment on this gist.

how to use manage.py syncdb outside of Django project, such as in Tornado?

I was looking through http://lincolnloop.com/blog/2009/sep/15/using-django-inside-tornado-web-server/ and I thought it was interesting and useful to use parts of Django if we need it in Tornado.
Based on the setup in http://lincolnloop.com/blog/2009/sep/15/using-django-inside-tornado-web-server/ how can we use manage.py syncdb ?
Here's what i have tried so far:
I've tried shifting manage.py to the same folder as the tornado project, and ran manage.py syncdb but it returns saying that settings.py is not found.
than i tried to move setting.py to the same folder and ran manage.py again. It tells me that no fixtures found. This time round, I have no idea how to configure settings.py since this is not a Django project.
Any advice or thoughts?
=================updates======================
Hi all,
continuing from the above an using advice provided by Agos,
i've tried running python manage.py syncdb --settings=dj_tornado and it returns
`"Error: Can't find the file 'settings.py'` in the directory containing 'manage.py'`. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.
(If the file settings.py does indeed exist, it's causing an ImportError somehow.)"
So what i did is to run django-admin.py syncdb --settings=dj_tornado and it returns "django.core.exceptions.ImproperlyConfigured: You haven't set the database ENGINE setting yet."
But the weird thing is that the database engine has been set. How would I go about fixing this? i'm using django 1.2.3 and Tornado 0.2 by the way.
=================updates again======================
Hi all,
i've applied the advice provided by Agos, with a settings.py file in teh same folder as manage.py, and ran the command django-admin.py syncdb --settings=dj_tornado.
I still received the error:
django.core.exceptions.ImproperlyConfigured: You haven't set the database ENGINE setting yet.
But i have already configured the database based engine as follows:
in dj_tornado.py:
from django.conf import settings
settings.configure(
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'dev.db',
}
}
)
I'm kind of at my wits end. How do i use syncdb outside of Django project?
Best.
If I got it correctly, you can just use the --settings switch to point manage.py to the dj_tornado.py, which is your settings file after all
Update 1
from the help, available at python manage.py help:
Options:
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
So I would try this:
python manage.py syncdb --settings=dj_tornado
Update 2
Another error, another update to the answer!
First of all, consider that that blog post is quite old (september 2009). Django's DATABASES setting has been updated since 1.2.
The syntax in the blog post was:
settings.configure(DATABASE_ENGINE='sqlite3', DATABASE_NAME='dev.db')
With Django 1.2.X this is surely not correct. This would be the equivalent version:
settings.configure(DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'dev.db'
}
})
(sorry for the horrible formatting of the code).
If this still won't work, I'd consider creating a “standard” Django settings file to import. But my bet is on the db settings syntax.
Last update, I swear
Have you tried using django-admin.py again with the new syntax? If so, and still didn't work, a minimal settings.py would be just this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'dev.db'
}
}
You can also keep the original configuration inside dj_tornado.py and use settings.py just to do syncdb.