Djongo Using ArrayField throws Apps No Loaded Error on makemigrations - django

I am trying to create a django model using djongo which uses ArrayField
class SubModel(models.Model):
i = models.IntegerField()
class Meta:
abstract = True
class BiggerModel(models.Model):
subarr = models.ArrayField(model_container=SubModel)
When I run makemigrations, I get the error
AppRegistryNotReady("Models aren't loaded yet.")
This is happening only if I use ArrayField. Not with any other fields
I am using django 2.1.5 and djongo 1.3.2

It's a bug on Djongo 1.3.2. You can downgrade it to 1.3.1 or wait for a new release (until today, 23/Apr, there was a PR merged, but not a new release)

Related

djongo JSONField rename causes "Cannot alter field" error

I have a Django application with djongo as a database engine. There's a JSONField in one for the models:
my_field = JSONField(default=list)
I modified the model and renamed my_field in Database like this
my_field = JSONField(default=list, db_column="myField")
Now when I create migrations:
makemigrations
I got an error:
ValueError: Cannot alter field my_app.MyModel.my_field into my_app.MyModel.my_field - they do not properly define db_type (are you using a badly-written custom field?)
Djongo version: "^1.3.6"
Django version: "^4.1.1"
How to fix the error?

Django Admin Not Showing Complete Fields In a Model

I am quite new to the Django environment, Here's a problem I am facing:
First I made a model:
class ABC(Model):
field A
field B
field C
then, I migrated them successfully using the following commands:
python manage.py makemigrations
python manage.py migrate
Then, I again added a new field to same model:
class ABC(Model):
#rest fields are here
field D
These also got migrated successfully.
But, Here's the problem now.
After migration, I am not able to see field D in the Django admin interface. (for which I want to edit the value)
AM I missing anything here?
(PS: Have tried sqlflush, dbshell every possible troubleshoot)
I also restarted NGINX & Gunicorn (since I am hosted on AWS EC2)
I am certain, that fields are getting created.
Please help.
First, check the admin.py file and admin.ModelAdmin class of this model.
from django.contrib import admin
from .models import ABC
#admin.register(ABC)
class ABCAdmin(admin.ModelAdmin):
fields = ['A', 'B', 'C', 'D']

Ignoring errors in makemigrations that can be silenced by in system check, Django 2.0

Using a version of django-proxy-overrides, I'm overriding a field in a Proxy model that appears a the base model. I'm using Django 2.0
This would cause Django's system check framework to complain, but in my settings file I have set:
SILENCED_SYSTEM_CHECKS = ["fields.E305", "fields.E304", "models.E006",
"models.E017"]
so python manage.py runserver works fine (and the overriding works beautifully).
However, when I run python manage.py makemigrations, Django raises an exception complaining about the clash in names:
django.core.exceptions.FieldError: Local field 'person' in class 'ProxyBillSponsorship' clashes with field of the same name from base class 'BillSponsorship'.
Is there anyway around this? I have tried setting
class Meta:
managed=False
on the the proxied models in the hope that makemigrations would ignore these models, but no luck.

Django 2.1 and select_related()

This is a follow-up / clarification to this question.
I'm using Django 2.1, Python 3.6, and Oracle 12c.
Suppose I have two models:
class ModelA(models.Model):
modelB_field = ForeignKey(ModelB, on_delete=models.DO_NOTHING)
example_field = models.IntegerField()
class ModelB(models.Model):
example_field = models.IntegerField()
Then if I do
ModelA.objects.filter(...).select_related('modelB_field')
I get
django.db.utils.DatabaseError: ORA-00918: column ambiguously defined
Three observations:
I only get the error if the field example_field is in both
models...even though it is not the primary key of ModelB.
The query that Django generates works in sqldeveloper.
The code works if I use a virtualenv with Django 2.0 instead of Django
The docs don't indicate anything changed with select_related in Django 2.1.
Definitely, its a bug on django 2.1, try downgrading to 2.0...

Django + mongoengine, connect to mongo when used as auxiliary database

I'm trying to connect to mongodb using mongoengine.
Mysql is my default database, and I have 'mongoengine.django.mongo_auth' in my installed apps. I removed the 'AUTH_USER_MODEL = 'mongo_auth.MongoUser'' due to errors about not having a default connection.
I use mongo with celery so I don't think there's a problem with the setup. This is how I am attempting to connect - the code is in views.py
from mongoengine import connect
my_connect = connect('my_db', alias='mongo')
test = test(name='a_name', desc='a desc')
test.save(using='mongo')
my_connect.connection.disconnect()
Have finally managed to sort this out:
#settings.py
from mongoengine import register_connection
register_connection(alias='default',name='db_name')
#models.py
from mongoengine import Document, StringField (etc)
class my_col(Document):
field_a = StringField()
#in your app
from mongoengine import connect
my_con = connect('db_name', alias='default')
item = my_col(field_a='something')
item.save()
my_con.disconnect()