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?
Related
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)
I just switched out the django User model for a CustomUser model. I've got a field called contributor_id in a Project model which is a m2m field connected to the User model. I've told the m2m field to point to the CustomUser model and have run makemigrations and migrate but the user_id field has not changed to customuser_id. This is causing the following error:
Unknown column 'projects_project_contributor_id.customuser_id' in 'field list'
I found these bug reports: bug1 and bug2 but they both appear to have been fixed in 2.0. Obviously I can just run an alter table query on my database, but I don't know if:
a) There's away to get the django orm to do the change, and
b) if altering the tables directly will get my migrations out of wack.
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.
i had a profile field in todo models which a ForeignKey to Profile model
Instead of using profile i want to use the user field of User model as a ForeignKey .
Steps:
I have removed the profile field from todo model, created and applied migration for that.
Works fine, profile field do not exist in database.
2, I added user field as a ForeignKey in todos models .
When doing python manage.py schemamigration todos --auto
gives response like:
Nothing seems to have changed.
what am missing here ?
Currently programming in Python Django 1.4. In my files I have written CREATE TABLE functions for productos and clientes to be created in the MySQL database. When I checked with python manage.py sqlall ventas (ventas being the parent directory of productos and clientes), it outputs that snippet of code. However, when I tried to access them under localhost admin, I got the
1146, "Table 'demo.ventas_cliente' doesn't exist" error. And these 2 tables do now show up in MySQL.
Initially I had dropped these 2 tables because there were some DB errors. I ran syncdb again but does not seem to retrieve those 2 tables. What seems to be wrong?
I strongly suggest you don't type MySql commands directly, this may throw you many errors in the future. To create tables in Django you must create models. For example:
1) In ./Yourproject/apps/yourDBName create __ init __.py
2) in settings.py under "installed apps" add your new app. Example: yourproject.apps.yourapp
4) execute "python manage.py runserver"
5) create models.py into your new app
6) now you can create your models like that:
class myTable(models.Model):
name = models.CharField(max_length=50)
email = models.EmailField()
7) if you want to access your new table from the admin, create admin.py in your app and type:
from django.contrib import admin
from models import myTable
admin.site.register(myTable)
#here, you can add more tables to the admin in the future
also, if you need to use foreign keys:
class parentTable(models.Model):
idParent = models.AutoField(primary_key=True)
parentName = models.CharField(null=False)
class childTable(models.Model):
idChild = models.AutoField(primary_key=True)
MyParentName = models.ForeignKey(parentTable, to_field='parentName')
childName = models.CharField(null=False)
MORE INFO: https://docs.djangoproject.com/en/dev/topics/db/models/