I'm a front-end dev struggling along with Django. I have the basics pretty much down but I've hit at wall at the following point.
I have a site running locally and also on a dev machine. Locally I've added an extra class model to an already existing app, registered it in the relevant admin.py and checked it in the settings. Locally the new class and relevant fields appear in admin but when I move this all to dev they're not appearing. The app is called 'publish'.
My method was as follows:
Created the new class in the publish > models.py file:
class Whitepaper(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(max_length=100, blank=True)
pub_date = models.DateField('date published')
section = models.ForeignKey('Section', related_name='whitepapers', blank=True, null=True)
description = models.CharField(max_length=1000)
docfile = models.FileField(upload_to="whitepapers/%Y/%m/%d", null=True, blank=True)
Updated and migrated the model with South using:
python manage.py schemamigration publish --auto
and
python manage.py migrate publish
Registered the class in the admin.py file:
from models import Section, Tag, Post, Whitepaper
from django.contrib import admin
from django import forms
admin.site.register(Whitepaper)
The app is listed in the settings.py file:
INSTALLED_APPS = (
...,
...,
'publish',
...,
)
As this is running on a dev server that's hosting a few other testing areas, restarting the whole thing is out of the question so I've been 'touching' the .wsgi file.
On my local version this got the model and fields showing up in the admin but on the dev server they are nowhere to be seen.
What am I missing?
Thanks ye brainy ones.
I figured out the problem. Turns out the login I was using to get into the admin didn't have superuser privileges. So I made a new one with:
python manage.py createsuperuser
After logging in with the new username and password I could see all my new shiny tables!
Are you sure touching .wsgi file does restart your app?
It looks like it doesn't.
Make sure the app is restarted. Find the evidence touching .wsgi file restarts the app maybe.
Since you don't provide any insight about how the dev server runs the apps, we won't be able to help you any further.
Related
I've deployed my application to DigitalOcean. Everything works fine except this situation. I've added new GeneralComplaintDocument model, made migration locally, pulled from Github last version of project on DigitalOcean's server, deleted all migration files, migrated again, but still getting this error:
relation "documents_app_generalcomplaintdocument" does not exist
LINE 1: INSERT INTO "documents_app_generalcomplaintdocument"
models.py:
class Document(models.Model):
created_date = models.DateTimeField(default=timezone.now)
added_by = CurrentUserField()
class GeneralComplaintDocument(Document):
complaint_reason = models.CharField(max_length=500)
result = models.CharField(max_length=500)
def __str__(self):
return self.complaint_reason
P.S: everything works fine on local server.
I would suggest for do something like this:
first delete all migrations files in your app(documents_app)and next execute the below SQL query in your Database. Here we assume your app_name is documents_app.
delete FROM "django_migrations" WHERE "app" = 'documents_app';
then migrate ,
python manage.py makemigrations documents_app
python manage.py migrate documents_app
I have a model like this :
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
address = models.CharField(max_length=100)
city= models.CharField(max_length=100)
, after a while, I add 2 more fields to this:
zip_code = models.CharField(max_length=20, blank=True, null=True)
state = models.CharField(max_length=50, blank=True, null=True)
, then I do the routine
python manage.py makemigrations
python manage.py migrate
But when I go to website/admin and check that model in Django Administration, I got the error "column user_profile.zip_code does not exist"
I search for the solution and some threads suggested to use South but then I learned that from django >= 1.7 we don't need to use South for migrations.
Please show me where I am wrong.
Thank you!
Check that you use the same settings when running migrate and the server.
If you are using django debug toolbar in your installed apps. Make sure to comment that, that gives the issue. If not, you can also check if your models are used by forms in another app or not. If they are its better to move the logic into views.
I commented out the debug toolbar, but that did not solve the problem.
I was adding a field to the user model. I have a utility that returns the default user. When I tried to migrate (adding the new field), that utility was getting called and was causing the error.
The solution that worked for me: in the utility that returns the default user, temporarily commenting out calls to the user table, and returning None for the default user. Migrate then ran successfully. Then of course I restored the code in the utility.
I found out that my utility was causing the problem by finding a line from my code in long list of exceptions displayed in the terminal.
How do I change a Django app's name in the admin?
I'm using Django 1.6.10
I've tried this:-
class MyModel(models.Model):
pass
class Meta:
app_label = 'My APP name'
but nothing happens.
I strongly recommend you upgrade to the latest 1.7.X, or ideally, Django 1.8.X. Django 1.6 is end of life, and does not support security updates.
The app_label should be a package name, e.g. myapp. It is not meant to be used as a human friendly string e.g. 'My App'. Doing this might break things.
The Django app loading was refactored in Django 1.7. In Django 1.7+, you can change the displayed application name by setting verbose_name for your app config. I'm afraid I don't know of a way to change the display of the app name for Django < 1.7.
write this code at the bottom of urls.py
admin.site.site_header = 'My APP name'
I am currently involved in a project where I am using Django 1.7 development version.I want to propogate changes that I make in my models (adding a field, deleting a model, etc.) into the database schema using "makemigrations" and "migrate" commmands.I added a "age" field to one of the models in my application.
country = models.CharField(max_length=50, blank=True)
address = models.CharField(max_length=100, blank=True)
postal_code = models.IntegerField(max_length=50, blank=True)
city = models.CharField(max_length=50, blank=True)
phone_no = models.CharField(max_length=25, blank=True)
skype_name = models.CharField('Skype Username',max_length=50, blank=True)
age=models.IntegerField(max_length=25,blank=True)
When I use "makemigrations" command ,the output is like---"No changes detected".I guess that "makemigrations" is not able to figure out the changes made to the schema.Any suggestions how can I make it work??
If you are adding initial migrations to an app, you must include the app name when using the makemigrations command.
python manage.py makemigrations your_app_label
If it is the first time you are migrating that app you have to use:
manage.py makemigrations myappname
Once you do that you can do:
manage.py migrate
If you had your app in database, modified its model and its not updating the changes on makemigrations you probably havent migrated it yet.
Change your model back to its original form, run the first command (with the app name) and migrate...it will fake it. Once you do that put back the changes on your model, run makemigrations and migrate again and it should work.
I have sometimes the same problem.
I manage to populate the change in the database by following :
rm -rf your_app/migrations/*
python manage.py migrate
if it doesn't work, consider a manual drop table before, if you don't have data in it.
it worked for me with django 1.7c1
I'm hosting a Django site through mod_wsgi and WAMP with Python 2.7. On my admin site the Users, Groups and Sites sections all have Add and Change buttons. While there is a section each for both of my own custom models, Feedpost and Newspost, they have no buttons at all and there is no way to add or change them.
I believe this change came about when I switched from using the Django internal testing server to using WAMP. Does anyone know what's causing this and how to get my Add and Change buttons back?
EDIT:
Here's one of the two models:
from django.db import models
from django.contrib import admin
class FeedPost(models.Model):
title = models.CharField(max_length=50)
text = models.CharField(max_length=5000)
date = models.DateTimeField('Date Published')
def __unicode__(self):
return self.title
admin.site.register(FeedPost)
The other is nearly exactly the same.
It turns out that using the Django development server localhost:8000/admin insists on going to my site's homepage and I can't access the admin site at all.
Also I think this is going to turn out to be the problem because I haven't got an admin.py file anywhere in my project...
These need to be in the admin.py file for starters.
from django.contrib import admin
admin.site.register(FeedPost)