I am trying to get Django running on Google App Engine using Django non-rel. I am following the Django 1.5 tutorial However, when i run:
python manage.py sql polls
nothing is returned. Can anyone suggest why 'manage.py sql' is silently failing?
When I sync the database I get:
$ python manage.py syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
The database is specified in settings.py as follows:
# Activate django-dbindexer for the default database
DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': DATABASES['default']}
AUTOLOAD_SITECONF = 'indexes'
and I have remembered to include 'polls' in the settings.py
INSTALLED_APPS = (
# 'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'djangotoolbox',
'autoload',
'dbindexer',
'polls',
# djangoappengine should come last, so it can override a few manage.py commands
'djangoappengine',
)
and the models are present in polls/models.py
from django.db import models
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
NOTE: If I change settings.py to use a local sqlite3 database, 'manage.py sql polls' behaves as described in the tutorial. Therefore, as far as I can tell, this has nothing to do with:
the /polls directory structure
the /polls/models.py file
the python path
Why do you expect it do anything? GAE is, specifically, a non-relational (NoSQL) datastore. There is quite simply no SQL to produce.
You should be aware that GAE, even with django-non-rel, is quite different from standard Django, and following the Django tutorial is only likely to confuse you.
Related
I have tried everything I can think of and find on here but nothing seems to be able to get my models to register and show on my Django Admin page. Weird thing is I have another model that is already appearing on the Admin page that I've matched the syntax for but that one works and this other one does not.
models.py
class SimpleModel(models.Model):
something = models.CharField('Simple Model', max_length=200, default='foobar')
def __str__(self):
return self.name
admin.py
from .models import SimpleModel
admin.site.register(SimpleModel)
settings.py
INSTALLED_APPS = [
'bootstrap4',
'app.apps.RequestsDashboardConfig',
'applications_dashboard',
'requests_dashboard',
#'applications_dashboard.apps.ApplicationsDashboardConfig',
'requests_dashboard.apps.RequestsDashboardConfig',
#"app.requests_dashboard",
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
You can see I've even tried multiple variations of the INSTALLED_APPS but even this still does not work. I don't even get any errors when I start the server with this series of commands after deleting the migrations.
python3 manage.py flush
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py createsuperuser
python3 manage.py runserver 0.0.0.0:80
I even tried deleting the entire DB, recreating it, and then running this again and still no luck!
Not sure where I went wrong in the end but for anyone who encounters similar issues to mine, I was able to solve this by doing another complete DB rebuild.
I am just trying out django channels so I created a virtual environment and installed django, drf and channels. It threw error asking for visual c++ build tools which got resolved after installing it. Then I created a channels project and an app. Then just for testing I added a sample model as below and registered it with the admin. It compiled well and also I was able to see the model in the admin page.
My Model Calss
from django.db import models
# Create your models here.
class College(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=150)
objects = models.Manager()
def __str__(self):
return self.name
My admin.py
from django.contrib import admin
from .models import College
# Register your models here.
admin.site.register(College)
Now the Problem
I added channels to the INSTALLED_APPS list in the settings.py file like below,
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'channelApp',
'channels',
]
Now when I try to run the server using the runserver command I get the following error
ModuleNotFoundError: No module named 'win32api'
LookupError: No installed app with label 'admin'.
I have been searching but failed to find any suitable answer. Kindly help me out.
Thanks in advance.
Just after I posted this I stumbled onto a SO post
Issue after installing django channels
Just to reiterate in short, this is an open bug and the work around is to install the following package
pip install pypiwin32
After installing you may have to close and reopen the editor for the changes to reflect. And the error is resolved.
my settings.py:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'Mysite'
)
AUTH_USER_MODEL = 'Mysite.PortalUserAbstract'
my Mysite.models.py:
class PortalUserAbstract(AbstractUser):
is_client = models.BooleanField(default=False)
is_manager = models.BooleanField(default=False)
error message :
OperationalError at /accounts/signup/client/
no such table: auth_user
Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/signup/client/
Django Version: 1.6.5
Exception Type: OperationalError
Exception Value:
no such table: auth_user
when i do manage.py syncdb it creates table "Mysite_portaluserabstract" but the auth module still looks for auth_user table.
what am I missing?
You're using Django 1.6, which is very out-of-date - it pre-dates migrations, which will create the missing tables for you. You should upgrade to at least Django 1.11 as was mentioned in comments; if this is a new project, I would recommend using Django 2.1 as of this writing, as the new URL syntax is much friendlier for getting started. It seems to be a new project as you are just starting with a custom user model.
In short:
Create a new virtualenv
pip install django
django-admin startproject myproject && cd myproject
python manage.py startapp mysite
edit mysite/models.py and add the following:
class PortalUserAbstract(AbstractUser):
is_client = models.BooleanField(default=False)
is_manager = models.BooleanField(default=False)
edit myproject/settings.py and add:
AUTH_USER_MODEL = 'Mysite.PortalUserAbstract'
run python manage.py makemigrations
run python manage.py migrate
Then you should be off and running with the latest version of Django. It would probably do you well to go through the tutorial: https://docs.djangoproject.com/en/2.1/intro/tutorial01/
Good luck!
Following the Django tutorial (part 2), I can't seem to see my Polls app in my django admin panel after registering it. My screen looks a bit like this, with a distinct lack of a section for the Polls app:
What I've done so far (following parts of this answer and the tutorial itself):
Registered my app in the admin.py file.
Added it to INSTALLED_APPS in settings.py in my project folder.
Ran python manage.py makemigrations & python manage.py migrate without any changes (btw, for future readers - that's the new >1.8 incarnation of syncdb, I believe).
Made sure the user I'm signing in with has superuser priviliges (as per this answer).
Restarted my nginx.
I'm still hazy as to what the problem is or, for that matter, how to debug it.
My admin.py file:
from django.contrib import admin
from .models import Question
admin.site.register(Question)
My models.py file (notice the Question object):
import datetime
from django.utils import timezone
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
INSTALLED_APPS portion of my settings.py project file:
INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
As it turns out, I wasn't paying attention to the process in which the application was served.
So, riding on this answer, I figured out it breaks down like this:
nginx gets a URL, decides where to pull from - in our case, Gunicorn.
Gunicorn searches for the proper Python file to pull - in our case, Django.
Djnago gets executed and the app loads (including our admin panel).
In this case, after making the changes to the admin panel I've restarted nginx, but not Gunicorn. Restarting Gunicorn solved the problem, and if you looked at my last comment - nginx crashed because of a typo in my admin.py file (added well after writing this question, during my attempt to fix it, and thus does not appear in the OP).
I'm trying to use custom user model with Django CMS. I created new users app with this model:
users.models:
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
bio = models.TextField(max_length=500, blank=True)
location = models.CharField(max_length=30, blank=True)
birth_date = models.DateField(null=True, blank=True)
Here project settings:
settings:
INSTALLED_APPS = [
'djangocms_admin_style',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
'django.contrib.messages',
'users',
'cms',
'menus',
...
]
AUTH_USER_MODEL = 'users.User'
Why I have this error?
manage.py makemigrations users
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'cms.PageUser'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
in an app with no migrations; see https://docs.djangoproject.com/en/1.8/topics/migrations/#dependencies for more
I ran into same problem and I followed your instruction but on step 9 I encounter this error:
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency users.0001_initial on database 'default'.
I got it to work by reordering your step (without commenting out the AUTH_USER_MODEL and without commenting out users from installed apps)
Removed migrations folder from users app
Started with a blank database
Ran manage.py makemigrations users
Ran manage.py migrate
Ran manage.py makemigrations
Ran manage.py migrate
I ran into the same issue. Based on a reply to https://github.com/divio/django-cms/issues/3436 I did the following which worked for me:
Removed migrations folder from users app
Commented out users from installed apps
Commented out the AUTH_USER_MODEL bit
Started with a blank database
Ran manage.py makemigrations
Ran manage.py migrate
Put back the things, I commented out previously.
Ran manage.py makemigrations users
Ran manage.py migrate
I know it's an old post but it might help others.