django-user-accounts : no such table: account_passwordhistory - django

There are a lot of django-related posts with "no such table" error but none are coming from django-user-accounts module.
I am getting this error
sqlite3.OperationalError: no such table: account_passwordhistory
, and here are the steps:
Installed django-user-accounts:
$ pip install django-user-accounts
Collecting django-user-accounts
Downloading https://files.pythonhosted.org/packages/0c/4f/40f76395324d98b7f8717aad7e08ad6f86ba2714eb956be6070e0402988c/django_user_accounts-2.0.3-py2.py3-none-any.whl (106kB)
100% |████████████████████████████████| 112kB 2.8MB/s
.
.
.
Installing collected packages: django-appconf, django-user-accounts
Successfully installed django-appconf-1.0.2 django-user-accounts-2.0.3
in settings.py added
INSTALLED_APPS = [ . . .
'django.contrib.sites',
'account' ]
SITE_ID = 1
MIDDLEWARE = [
.
.
.
'account.middleware.ExpiredPasswordMiddleware',
]
ACCOUNT_PASSWORD_USE_HISTORY = True
ACCOUNT_PASSWORD_EXPIRY = 60 # number of seconds
restarted server and ran : $ python manage.py user_password_history
I got:
Traceback (most recent call last):
File "/Users/ipozdnya/miniconda3/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params)
File "/Users/someuser/miniconda3/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: account_passwordhistory
I realize that account_passwordhistory did not get created at the time of install or some other step. $ python manage.py makemigrations states that No changes detected. Nothing in this doc tells me what to do about it: http://blog.pinaxproject.com/2016/11/22/how-configure-password-expiration-for-your-site/
Thanks

Ok, my problem was that I trusted the output of $ python manage.py makemigrations
that stated that No changes detected. However, when I did run $ python manage.py migrate, it applied a new migration for account_passwordhistory and account_passwordexpire tables just fine:
Applying account.0003_passwordexpiry_passwordhistory... OK
And the tables are in the DB.
Setting my password to expire in 1 second (python manage.py user_password_expiry my_user_name --expire 1) however did not have any effect on the site functionality, but that's a different issue.

Related

I keep getting an error when trying to create a database in my Django Project

I deleted my database and migration files with the exception of init on purpose, I wanted to start fresh.
Using these commands:
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc" -delete
I then dropped the database. Commands did their job, deleted all the migrations files necessary
I then went on to create the table again:
python3 manage.py makemigrations
I get this error:
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: auctions_category
Things I've tried:
python3 manage.py syncdb (same error)
python3 manage.py migrate --run-syncdb (same error)

Django runs fine locally but one field doesn't exist after deploying to Heroku

I'm still relatively new to django. In my website, I created a new field group in AnonymousStudent model. My Django website runs fine on my local machine, but after deploying to Heroku it says the group field doesn't exist.
I got couple of errors when trying to access to different parts in my website.
One says:
ProgrammingError at ...
column "group" of relation "student_anonymousstudent" does not exist LINE 1: ...", "last_active_time", "associate_experiment_id", "group") V...
Another one says:
ProgrammingError at ...
column student_anonymousstudent.group does not exist LINE 1: ...dent_anonymousstudent"."associate_experiment_id", "student_a...
And the other one says:
InvalidCursorName at ...
cursor "_django_curs_139758823008000_sync_1" does not exist
The traceback for the last one says:
/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py in _execute
86. return self.cursor.execute(sql, params)
▶ Local vars
The above exception (column student_anonymousstudent.group does not exist LINE 1: ...dent_anonymousstudent"."associate_experiment_id", "student_a... ^ ) was the direct cause of the following exception: /app/.heroku/python/lib/python3.7/site-packages/django/db/models/sql/compiler.py in execute_sql
1144. cursor.execute(sql, params)
It seems like a migration problem, but when I tried to run python manage.py makemigrations it says nothing changed.
settings.py
DATABASES = {
"default": {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3')
}
}
if 'HEROKU_ENV' in os.environ:
ALLOWED_HOSTS.append(".herokuapp.com")
DATABASES["default"] = dj_database_url.config(
ssl_require=True,
engine="django_postgrespool2"
)
Procfile
release: bash release-tasks.sh
web: daphne giks.asgi:application -b 0.0.0.0 -p $PORT -v2
release-tasks.sh
python manage.py migrate
python manage.py loaddata fixtures/publications.json
python manage.py loaddata fixtures/awards.json
I have couple of questions here:
Apparently I'm using two different databases for local and Heroku environments. But I've specified in my Procfile to auto run migrations when deploying. So is this really a migration problem?
Still about the database. Can you use django_postgrespool2 with sqlite3?
What exactly is the problem? And how to fix it?
Please let me know if more information is needed. Thank you in advance.

django.db.utils.OperationalError: (1426, "Too big precision 200 specified for 'price'. Maximum is 65.")

I am trying to DecimalField I set the parameter max_digits to 200,
price = models.DecimalField(max_digits=200, decimal_places=2)
It showed the error:
django.db.utils.OperationalError: (1426, "Too big precision 200
specified for 'price'. Maximum is 65.")
price = models.DecimalField(max_digits=65, decimal_places=2)
So I changed it to 65, but it still it shows the same error:
django.db.utils.OperationalError: (1426, "Too big precision 200
specified for 'price'. Maximum is 65.")
After doing corrections in the model field
Delete the 'migrations' folder under 'your_app_name'
Run python manage.py makemigrations your_app_name
new table should have been created
Run python manage.py migrate
it worked for me with MySql , in Django 2.1.
After searching over the internet I did the following steps and it worked.
Delete your pycache from your app_name and also from inner project_name.
Run command python manage.py makemigrations
then run, python manage.py migrate**

ImportError at /admin/ No module named polls_ChoiceField.urls

Django 1.6.2
MacOSX 10.9.2
Python 2.7
I recently deleted a Django App "polls_ChoiceField" which was sitting inside another app "polls" as I was only using it to test a few things. However since i deleted it then the app it was sitting in no longer works.
I deleted the file through the pyDev package explorer. When I synced the Database it gave my the option of deleting the stale content, I selected yes.
Can anyone tell me what I have to do to get the original "polls" all running again?
Relevant Terminal output
localhost:src brendan$ python manage.py syncdb
Creating tables ...
The following content types are stale and need to be deleted:
polls | choice_choicefield
polls | poll_choicefield
Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.
Type 'yes' to continue, or 'no' to cancel: yes
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
I then synced the DB
localhost:src brendan$ python manage.py syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
And I am able to run the server
localhost:src brendan$ python manage.py runserver
Validating models...
0 errors found
When i try to revisit the app in my browser i get
ImportError at /polls/
No module named polls_ChoiceField.urls
Request Method: GET
Request URL: http://localhost:8000/polls/
Django Version: 1.6.2
Exception Type: ImportError
Exception Value:
No module named polls_ChoiceField.urls
Exception Location: /Library/Python/2.7/site-packages/django/utils/importlib.py in import_module, line 40
Python Executable: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.6
Python Path:
['/Users/brendan/Dropbox/workspace/bias_experiment/src',
'/Library/Python/2.7/site-packages/distribute-0.7.3-py2.7.egg',
'/Library/Python/2.7/site-packages/setuptools-2.2-py2.7.egg',
'/Library/Python/2.7/site-packages/pip-1.5.4-py2.7.egg',
'/Library/Python/2.7/site-packages/yolk-0.4.3-py2.7.egg',
'/Library/Python/2.7/site-packages/virtualenv-1.11.4-py2.7.egg',
'/Library/Python/2.7/site-packages/virtualenvwrapper-4.2-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
'/Library/Python/2.7/site-packages']
Server time: Mon, 28 Apr 2014 16:26:46 +0100
Thanks
EDIT:
My urls.py with the bad line of code (the middle url)
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls', namespace="polls")),
url(r'^polls_ChoiceField/', include('polls_ChoiceField.urls', namespace="polls_ChoiceField")),
url(r'^admin/', include(admin.site.urls)),
)
Thanks again.
Check your project-level urls.py, looks like it still tries to use urls from the deleted app.

createsuperuser invalid syntax in Django

I ran into a problem while going through my first Django tutorial.
I didn't create an initial superuser account during syncdb and I'm now trying to create it programmatically. The problem is that I'm getting an invalid syntax error when I run the command:
>>> django-admin.py createsuperuser
File "<stdin>", line 1
django-admin.py createsuperuser
^
SyntaxError: invalid syntax
I am running Django through Python tools for Visual Studio 2010.
Both 'django.contrib.auth' and 'django.contrib.admin' are enabled in settings.py.
Here is the tutorial that I'm following.
Looks like you are running the command in the django shell. You need to run this command in the command prompt/terminal instead.
Demo
(_env)k#dev:~/workspace/prj krav 48 $ ./manage.py shell
In [1]: manage.py createsuperuser
------------------------------------------------------------
File "<ipython console>", line 1
manage.py createsuperuser
^
SyntaxError: invalid syntax
Continued..
In [2]: exit()
Do you really want to exit ([y]/n)? y
(_env)k#dev:~/workspace/prj krav 48 $ ./manage.py createsuperuser
Username: