Django South DatabaseError: App inside app - Table doesn't exist - django

After being inspired by django-oscar, I tried to put a cmsplugin inside its main app. However, after doing a schemamigration --initial I can't use the plugin in Django CMS.
DatabaseError: (1146, "Table 'devel_test.cmsplugin_galleries_gallerycontainer_galleries' doesn't exist")
App Tree
gallery
apps
cmsplugin_galleries
migrations
cms_plugins.py
init.py
models.py
init.py
migrations
static
templates
admin.py
init.py
models.py
views.py
Gallery models
class Gallery(models.Model):
title = models.CharField(_(u'title'), max_length=200)
description = models.TextField(_(u'description'), blank=True)
image_folder = FilerFolderField(verbose_name=_(u'image folder'))
is_video = models.BooleanField(_(u'is video content'), default=False)
snippet = models.TextField(_(u'video snippet'))
class Meta:
verbose_name = _(u'Gallery')
verbose_name_plural = _(u'Galleries')
class GalleryImage(models.Model):
gallery = models.ForeignKey(Gallery, verbose_name=_(u'gallery'))
title = models.CharField(_(u'title'), max_length=200, blank=True)
src = FilerImageField(verbose_name=_(u'image'))
Cmsplugin_galleries models
class GalleryContainer(CMSPlugin):
title = models.CharField(_(u'title'), max_length=200)
galleries = models.ManyToManyField(Gallery, verbose_name=_(u'galleries'))
def __unicode__(self):
return u'%s' % self.title
Since I can properly run it using syncdb --all, what did I do wrong?
Notes:
Using syncdb creates a table with the name cmsplugin_galleries_gallerycontainer_galleries but using south, the table name is cmsplugin_gallerycontainer_galleries
Thanks

Since there was no other alternative I followed #daigorocub tip and replaced all the shorten_name instances of cmsplugin_gallerycontainer_galleries inside the migration file
m2m_table_name = db.shorten_name(u'cmsplugin_gallerycontainer_galleries')
to
m2m_table_name = db.shorten_name(u'cmsplugin_galleries_gallerycontainer_galleries')
This issue was fixed in the development branch of django cms 3.0 (https://github.com/divio/django-cms/issues/2291#ref-pullrequest-26529456) but since my version is older I couldn't update to the latest branch
Thank you guys for your help!

Related

makemigrations - No changes detected -Django

I am new to Django, and im trying to create a company profile for user to fill up.
when i make migrations, i got the following error which is no changes detect.
heres the model.py
class Company(models.Model):
name = models.CharField(max_length=100)
about = models.TextField(gettext_lazy('about'), max_length=500, blank=True)
role = models.CharField(max_length=100)
address=models.CharField(max_length=100)
contact=models.CharField(max_length=100)
def __str__(self):
return f'{self.user.username} Profile'
I didnt create anything in other .py file only model and i have another class which is profile in the same model.py as company.
Do correct or lmk if i make any mistake, thanks!
Your app must be included in INSTALLED_APPS first (inside settings.py).
INSTALLED_APPS = [
...
'<myapp>',
...
]
After that you can run
python manage.py makemigrations <myapp>

Why RelatedObjectDoesNotExist is thrown when trying to add an entery from the django admin?

In my models, I have the ImageAlbum model and Image model. In the Image model, I have a ForeignKey field to the ImageAlbum. This code is actually recommended from this article.
class ImageAlbum(models.Model):
def __str__(self):
return str(self.pk)
class Image(models.Model):
name = models.CharField(max_length=255)
image = models.ImageField(upload_to=get_upload_path)
default = models.BooleanField(default=False)
thumbnail = models.ImageField(upload_to=get_thumbnail_path, default='default/default_thumbnail.jpg')
album = models.ForeignKey(ImageAlbum, on_delete=models.CASCADE)
I registered the models in the admin and the Image form looks like that:
And after I hit save, the following exception occurs:
Your ImageAlbum Model should look like this .
class ImageAlbum(models.Model):
image = models.ImageField(upload_to='images/', blank=True) # new
def __str__(self):
return str(self.pk)
Migrate first and then Check again this would work.
I experienced the same issue, in my case it had to do with the migrations. I re-ran migrations afresh after clearing them out and that solved the issue you are highlighting. Of cause this was on a local dev environment with a SQLite db setup, you may not have such a luxury in production.

Django error: multiple default values for specified column "id"

I'm working with a project with docker-compose, where I have a postgre container.
When I run:
docker-compose -f dev.yml run django python manage.py migrate
I get the error:
django.db.utils.ProgrammingError: multiple default values specified for column "id" of table "scrapy_scrapy"
That is happening before I made some changes to my models.py file. But now the file is correct and should be working. This is the content of the models.py file:
from django.db import models
import django
# Create your models here.
class Scrapy(models.Model):
user = models.CharField(max_length=50,blank=True)
password = models.CharField(max_length=50,blank=True)
projecte = models.CharField(max_length=100)
estat_last_check = models.CharField(max_length=700, default="", blank=True)
date = models.DateTimeField(default=django.utils.timezone.now, blank=True)
app_label = ''
def __str__(self): # __unicode__ on Python 2
return self.projecte + " - " + self.user
class Meta:
app_label = 'scrapy'
As you can see, no id filed is defined anymore, so, why is complaining about that field?
I've done my research and tried some possible solutions, but no luck. I've already tried deleting the full Docker container and creating it again, or trying to delete the database.
Any ideas?

.py file is not compiled on django

I'm using django 1.6.1. I got one file name "payment.py" on models folder and it's not compiled to .pyc file. Even if I changed the file name to "payment_room.py", it still won't be compiled
The other model files have been compiled already and worked pretty well.
Because of that, django won't create the table on my database if I run syncdb command. I run validate command using manage.py, but it didn't return any error.
N.B.
It's still on debug & development mode. The web hasn't been deployed to apache server yet.
from django.db import models
from ghb_manager.models.reservation import Reservation
class Payment (models.Model):
class Meta:
app_label = 'ghb_manager'
PAYMENT_METHOD_CHOICES = (
('CA', 'Cash'),
('CR', 'Credit'),
('TR', 'Transfer')
)
payment_id = models.CharField(max_length=14, primary_key=True)
reservation_id = models.ForeignKey(Reservation)
ammount_tendered = models.DecimalField(max_digits=19, decimal_places=2)
payment_method = models.CharField(max_length=20, choices=PAYMENT_METHOD_CHOICES)
payment_date = models.DateField()
def __unicode__(self):
return self.payment_id
Please check your init.py in your models directory. You have to import all the models you create in models directory, like:
# __init__.py
from payment import Payment
Django looks into app.models for app's models.

Django Guardian TemplateSyntaxError In Admin

Trying to edit object permissions using django-guardian in the admin site I get this error.
Caught VariableDoesNotExist while rendering: Failed lookup for key [adminform] in u'[{}, {\'csrf_token\': }, {\'debug\': True, \'sql_queries\': [{\'stacktrace\':...
Template error
In template /Library/Python/2.7/site-packages/grappelli/templates/admin/change_form.html, error at line 34
The line where the error occurs.
var related_lookup_fields_fk = {% get_related_lookup_fields_fk adminform.model_admin %};
I'm using grappelli and south if that makes any difference.
My model
class Alert(models.Model):
"""Alert for product updates"""
product = models.ForeignKey(Product)
message = models.CharField(help_text="What has changed?",blank=True, max_length=200)
created = models.DateTimeField(auto_now_add=True, editable=False)
updated = models.DateTimeField(auto_now=True, auto_now_add=True, editable=False)
def __unicode__(self):
return u"%s" % self.message
class Meta:
ordering = ['-created']
permissions = (
('view_alert', 'View Alert'),
)
Admin.py
class AlertAdmin(GuardedModelAdmin):
pass
admin.site.register(Alert, AlertAdmin)
grappelli is the key here.
This is related issue #51 (https://github.com/lukaszb/django-guardian/issues/51) which was fixed with https://github.com/lukaszb/django-guardian/commit/a21b044711266534eaef5e58397d0701ec101058.
Unfortunately, I haven't released new django-guardian yet so you can try using pip to install package directly from github:
pip install -e git+git://github.com/lukaszb/django-guardian.git#a21b044711266534eaef5e58397d0701ec101058#egg=django-guardian-1.0.4.dev
Hope that helps.