Cannot add "simplejwt.token_blacklist" to install apps - python

Hi I'm having an issue with restframework_simplejwt library.
When I add blacklisting to installed apps ir returns me an error.
settings.py file:
INSTALLED_APPS = [
...
'rest_framework_simplejwt.token_blacklist',
...
]
error:
django.db.utils.ProgrammingError: relation "token_blacklist_outstandingtoken" does not exist
LINE 1: INSERT INTO "token_blacklist_outstandingtoken" ("user_id", "...

I realized that after adding the app to INSTALLED_APPS I didn't migrate the changes .
python manage.py migrate and problem solved.
Simple JWT docs gives us the necesary steps for this action.

Related

I keep getting no changes detected when migrating app in Django

I am following this video tutorial to learn Django: https://www.youtube.com/watch?v=F5mRW0jo-U4&t=909s
I am at the "Your first app component" section where he creates an app and then migrates it. I have followed every one of his steps so far yet I keep getting the no changes detected error when I migrate the app
I have tried researching ways to fix this but it doesn't seem like there is any one right way to do it, it's more of a case by case basis. I've made sure my app is under the install_apps section in the settings. I've tried python manage.py makemigrations but that tells me there are no changes detected. I've tried "python manage.py makemigrations product" to be more specific but it tells me that App 'product' could not be found. Is it in INSTALLED_APPS?" even though it is in installed apps
currently this is my installed apps section:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'product',
after migrate and makemigrations command put your app name
like this
python manage.py migrate product
python manage.py makemigrations product
my case it's working
You didn't add your app name in 'Installed_Apps' in settings.py. Add this first and then run again.
for a proper migrations with 'python manage.py makemigrations' make sure that after creating your model class you save them before you typing any console code very important

django-newsletter - no runjobs in manage.py commands?

Hi I'm reading the docs for using django-newsletter.
And it says to call the following admin command to actually send the emails:
./manage.py runjob submit
In other parts of the docs it says runjobs instead of runjob.
Anyways, I'm not seeing either runjob or runjobs in the list of commands ./manage.py help, even though the 'newsletter' app is in installed_apps and I can access it in the admin.
What am I missing?
I was missing django_extensions in INSTALLED_APPS. The actual requirements for django-newsletter in INSTALLED_APPS are:
INSTALLED_APPS = (
...
'sorl.thumbnail',
'django_extensions',
'newsletter',
...
)

How to delete existing migrations in Django 1.7

So i'm following the Tango with Django guide, specifically part 7.3.2. of the tutorial. After I ran the command python3 manage.py makemigrations rango, it won't let me re-populate the database using the populate script. Instead I got the error: django.db.utils.OperationalError: no such column: rango_category.slug.
Then, I tried to revert things back to normal by deleting all the slug code (so before 7.3 of the guide). I made a migration after doing so, but then because the prior migration which added the slug category was never deleted, I can't use the migrate command to revert my changes because it throws an error when it tries to migrate using the old Added category slug migration. Even when I specifically point to the newest migration, it still gives me an error for the old one.
Then, in an effort to fix things, I used a bunch of different migrate and makemigrations commands, including --empty, --fake, squashmigrations etc and now my migrations look unrecognizable. Is there a way to just delete all these existing migrations and just start from a completely clean slate?
This is what migrate --list looks like now, for reference:
admin
[ ] 0001_initial
auth
[ ] 0001_initial
rango
[ ] 0001_squashed_0003_category_slug (3 squashed migrations)
[ ] 0001_squashed_0005_auto_20150328_0917 (5 squashed migrations)
contenttypes
[ ] 0001_initial
sessions
[ ] 0001_initial
For a clean start.
Delete the migrations folder inside rango
delete database which created.Then restart your migration process
You don't need to delete the migrations folder, only the migrations files, but leave __init__.py there.

Django 1.7 - App 'your_app_name' does not have migrations

I am trying to upgrade from Django 1.6.7 to Django 1.7.1, so I have been trying to migrate my app.
I have followed the django docs here.
I deleted the south from my installed apps.
In the migration directory, I delete the numbered migration files and the .pyc files but I kept the directory & __ init__.py file.
I then run :
python manage.py makemigrations your_app_name
I receive the following confirmation message:
Migrations for 'your_app_name':
0001_initial.py:
- Create model UserProfile
Next I run:
python manage.py migrate your_app_name
I received the following error:
CommandError: App 'your_app_name' does not have migrations (you cannot selectively sync unmigrated apps)
As per the docs, I also ran:
python manage.py migrate --fake your_app_name
I received the same error message:
CommandError: App 'your_app_name' does not have migrations (you cannot selectively sync unmigrated apps)
Can anyone shed some light on why this will not work for me?
I noticed that only those apps that actually contain a migrations folder that contain a file __init__.py are recognized by migrations. IE having only models.py in your app is not enough.
If you have a single app, running migrate without specifying the app or migration may work.
If so, the first thing to check is that your app name matched that specified in your settings.py under INSTALLED_APPS.
As pointed out in the comments, app names can be in the form [parent_app].[app_name]. In this case, migrate needs [app_name] only.
Your app must contain a models.py file (even emtpy).
Source: https://groups.google.com/forum/#!msg/django-users/bsTZEmxgDJM/wH0p3xinBWIJ
Just to mention another possible reason:
In my Django app i added the correct migrations and installed the app with pip and got the same error.
What i was missing is a correct MANIFEST.in file
Also the parameter include_package_data in setup() from the setup.py file was not set to True.

"python manage.py syncdb" not creating tables

I first ran
python manage.py syncdb
and it created the database and tables for me, then I tried to add more apps, and here's what I did:
create apps by
python manage.py startapp newapp
Then I added 'newapp' to INSTALLED_APPS in setting.py:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'newapp',
)
At last I ran syncdb:
python manage.py syncdb
and here's the result I get:
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
I checked my db and there is no table named newapp, no table's name including newapp.
I also ran into this issue, and was able to get around it by removing the migrations folder inside my app. Somehow that had already gotten created and was tricking syncdb into thinking that it was fully migrated already, but those migration scripts didn't actually do anything useful. Obviously don't try this if you actually have migrations you want to save, but I was working with a brand new app and models.
If you run:
python manage.py inspectdb > somefile.txt
You can get quickly check out if your database structure is matching your django models.
I tried most of the ideas above:
making sure the models.py is imported (verified that the module executed during a makemigrate),
deleting the migrations folder
setting managed = True (this is default anyways),
used the python manage.py inspectdb (which correctly dumped the table, if I had created it manually).
The key was simply to run a makemigrations on the app separately:
python manage.py makemigrations <app_name>
as part of performing the makemigrations step. Then you do
python manage.py migrate
afterwards as usual.
(applies to Django 1.10, using Postgres 9.5).
Django documentation
Credit, related post
i got same problem, but i didn't have any "migration" folder. I solved it like below.
I just added app_label with the model code,
class MyModel(models.Model):
...
class Meta:
managed = True # add this
app_label = 'myapp' # & this
Also, make sure it is discoverable by referencing it in myapp/models/__init__.py
from model_file.py import MyModel
You should be using this command
python manage.py migrate
where you were runing syncdb from the location where manage.py resides
I was having the same problem and noticed that it had created a db.sqlite3 file that didn't seem empty:
$ ls -l
-rw-r--r-- 1 sauron staff 122880 Jul 31 01:22 db.sqlite3
I tried running sqlite again using the filename as an argument and that worked:
$ sqlite3 db.sqlite3
SQLite version 3.7.13 2012-07-17 17:46:21
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .schema
CREATE TABLE "auth_group" (
"id" integer NOT NULL PRIMARY KEY,
"name" varchar(80) NOT NULL UNIQUE
);
... many rows ...

Categories

Resources