Why Django doesnt migrate my altered model? - python

Hi i have a django model as below:
from django.db import models
class ClientProfile(models.Model):
id = models.AutoField(primary_key=True)
firstname = models.CharField(max_length=100,blank=False)
lastname = models.CharField(max_length=100,blank=False)
gender = models.CharField(max_length=6,blank=False)
birthdate = models.DateField(blank=False)
nationality = models.CharField(max_length=100,blank=False)
education = models.CharField(max_length=100,blank=True)
occupation = models.CharField(max_length=100,blank=True)
i have created this model with email field initially. but then i decided to deduct it.
now i get this error when i migrate:
django.db.utils.OperationalError: near "AUTOINCREMENT": syntax error
and then i deleted my database and migrated again and i get the same message again. I tried deleting my app view and then start from scrach(creating a new migration and creating a new superuser and then add the model again) and still got the same error. i even tried rollback to initial migrations and then migrate again but got the email field back again and the new migration didn't change it. what can i do?
and these are my migrations:
and this is my stacktrace:
D:\University\UT\Thesis\My Project\App\AdjustServer>python manage.py migrate
Operations to perform:
Apply all migrations: AdjustRest, admin, auth, contenttypes, sessions
Running migrations:
Applying AdjustRest.0001_initial... OK
Applying AdjustRest.0002_clientprofile_nationality... OK
Applying AdjustRest.0003_auto_20190313_2158... OK
Applying AdjustRest.0004_auto_20190313_2205...Traceback (most recent call last):
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\utils.py", line 83, in _execute
return self.cursor.execute(sql)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\sqlite3\base.py", line 296, in execute
return Database.Cursor.execute(self, query)
sqlite3.OperationalError: near "AUTOINCREMENT": syntax error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 353, in execute
output = self.handle(*args, **options)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
fake_initial=fake_initial,
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\operations\fields.py", line 216, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 136, in alter_field
super().alter_field(model, old_field, new_field, strict=strict)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\schema.py", line 523, in alter_field
old_db_params, new_db_params, strict)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 333, in _alter_field
self._remake_table(model, alter_field=(old_field, new_field))
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 266, in _remake_table
self.create_model(temp_model)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\schema.py", line 312, in create_model
self.execute(sql, params or None)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\schema.py", line 133, in execute
cursor.execute(sql, params)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\utils.py", line 83, in _execute
return self.cursor.execute(sql)
File "C:\Users\Parsa\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\sqlite3\base.py", line 296, in execute
return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: near "AUTOINCREMENT": syntax error
AdjustRest.0004_auto_20190313_2205:
# Generated by Django 2.1.7 on 2019-03-13 18:35
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('AdjustRest', '0003_auto_20190313_2158'),
]
operations = [
migrations.AlterField(
model_name='clientprofile',
name='email',
field=models.EmailField(max_length=254, primary_key=True, serialize=False),
),
migrations.AlterField(
model_name='clientprofile',
name='id',
field=models.IntegerField(default=1),
),
]

Try without id = models.AutoField(primary_key=True), which is redundant as Django automatically assigns a primary key named id if you don't specify a different primary key.
If it still fails, show the code from the migration file.

Related

django.db.utils.DataError: value too long for type character varying(30). I am getting this error while migrating on heroku postgresql

The errors I am getting while migrating on PostgreSQL Heroku. Note: It is working fine on the local server.
Traceback (most recent call last):
File "/app/manage.py", line 22, in <module>
main()
File "/app/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 244, in handle
post_migrate_state = executor.migrate(
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
state = migration.apply(state, schema_editor)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/migrations/migration.py", line 126, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/migrations/operations/fields.py", line 104, in database_forwards
schema_editor.add_field(
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 522, in add_field
self.execute(sql, params)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 145, in execute
cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
**django.db.utils.DataError: value too long for type character varying(30)**
there is no column with 30 lengths even tried migrating after deleting all data and still getting the same error.
This is the model of the project
models.py
from django.db import models
from django.contrib.auth.models import User
from django.db.models.fields import AutoField
from django.utils.timezone import now
class pageinfo(models.Model):
page_id=models.IntegerField(AutoField,primary_key=True);
# thumbnail=models.ImageField(null=True,blank=True);
channellink=models.URLField(null=True,default='#')
logo= models.URLField(null=True,blank=True);
youtube_link1=models.URLField(null=True,default='#')
youtube_link2=models.URLField(null=True,default='#')
title=models.CharField(max_length=150,null=True);
display_title=models.CharField(max_length=150,null=True);
subscriber=models.CharField(max_length=15,null=True);
description=models.TextField(null=True)
ratingtitle1=models.CharField(max_length=150,default='Course Depth')
ratingtitle2=models.CharField(max_length=150,default='Language Clarity')
ratingtitle3=models.CharField(max_length=150,default='How interactive videos are')
ratingtitle4=models.CharField(max_length=150,default='Quality of Content')
# Create your models here.
class review(models.Model):
# id=models.ForeignKey(pageinfo,on_delete=models.CASCADE,primary_key=True)
comment=models.CharField(max_length=1000,null=True);
type=models.CharField(max_length=120,null=False)
username= models.ForeignKey(User,on_delete=models.CASCADE, null=True);
timeStamp=models.DateTimeField(default=now)
class rating(models.Model):
# id=models.ForeignKey(pageinfo,on_delete=models.CASCADE,primary_key=True)
rate=models.IntegerField();
type=models.CharField(max_length=120,null=False)
username= models.ForeignKey(User,on_delete=models.CASCADE,null=True);
email=models.CharField(max_length=80,default='')
timeStamp=models.DateTimeField(default=now)
class languagerating(models.Model):
# id=models.ForeignKey(pageinfo,on_delete=models.CASCADE,primary_key=True)
rate=models.IntegerField();
type=models.CharField(max_length=120,null=False)
email=models.CharField(max_length=80,default='')
username= models.ForeignKey(User,on_delete=models.CASCADE,null=True);
timeStamp=models.DateTimeField(default=now)
class interactionrating(models.Model):
# id=models.ForeignKey(pageinfo,on_delete=models.CASCADE,primary_key=True)
rate=models.IntegerField();
type=models.CharField(max_length=120,null=False)
email=models.CharField(max_length=80,default='')
username= models.ForeignKey(User,on_delete=models.CASCADE,null=True);
timeStamp=models.DateTimeField(default=now)
class qualityrating(models.Model):
# id=models.ForeignKey(pageinfo,on_delete=models.CASCADE,primary_key=True)
rate=models.IntegerField();
type=models.CharField(max_length=120,null=False)
email=models.CharField(max_length=80,default='')
username= models.ForeignKey(User,on_delete=models.CASCADE,null=True);
timeStamp=models.DateTimeField(default=now)
# class user_detai(models.Model):
# username=models.CharField(max_length=50);
# email=models.CharField(max_length=50)
# password=models.CharField( max_length=50)
class Info(models.Model):
name=models.CharField(max_length=40,default='')
email=models.CharField(max_length=80, null=True, );
comment=models.CharField(max_length=1000, null=True);
I just deleted the junk file inside the migrations>pycache
In your pageinfo model, it looks like you have
subscriber=models.CharField(max_length=15,null=True);
Try increasing the max_length for this field and re run your makemigrations and migrate command.
The error is due to already saved data in your database being longer than the given characters. You may want to look at the data and consider fixing it or whether the given characters are really the limit you want.
If you are maintaining history for the model then you also need to delete data in the history table.

django.db.utils.OperationalError: no such table: Recruiter_jobs table not found error?

I Am doing a project in Django and I have created some models in my project and after migrating it gives me something error like Django.db.utils.OperationalError: no such table: Recruiter_jobs, but I think I have all the tables registered in admin also. but still, it showing an error...
here's my models.py
class empDetail(models.Model):
cmpName=models.CharField("Company Name ",max_length=30)
role=models.CharField("role ",max_length=20)
def __str__(self):
return self.empEmail
class jobs(models.Model):
location=models.CharField("Location ",max_length=30)
desc=models.CharField("Descriptions ",max_length=3000)
role=models.CharField("role ",max_length=10)
sal=models.CharField("salary ",max_length=20)
def __str__(self):
return self.desc
class candetail(models.Model):
location=models.CharField("Locations ",max_length=30,default="")
role=models.CharField("Role ",max_length=100,default="")
cv=models.FileField(upload_to="media/canDetails/")
def __str__(self):
return self.location
class availablejob(models.Model):
cmpny=models.CharField("Company Name",max_length=100,default="")
location=models.CharField("Location ",max_length=30)
desc=models.CharField("Descriptions ",max_length=3000)
role=models.CharField("Role ",max_length=100)
sal=models.CharField("Salary ",max_length=20)
def __str__(self):
return self.role
class empDetails(models.Model):
cmpName=models.CharField("Company Name ",max_length=30)
role=models.CharField("role ",max_length=20)
cv=models.FileField(upload_to="media/empDetails/")
def __str__(self):
return self.empEmail
heres the logs below
(env) PS C:\Users\ashwi\Documents\GitHub\AMCH\AMCH_Recruiter> python manage.py migrate
Operations to perform:
Apply all migrations: Recruiter, admin, auth, contenttypes, sessions
Running migrations:
Applying Recruiter.0008_delete_jobs...Traceback (most recent call last):
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 423, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: Recruiter_jobs
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\ashwi\Documents\GitHub\AMCH\AMCH_Recruiter\manage.py", line 22, in <module>
main()
File "C:\Users\ashwi\Documents\GitHub\AMCH\AMCH_Recruiter\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\core\management\base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\core\management\commands\migrate.py", line 244, in handle
post_migrate_state = executor.migrate(
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\migrations\executor.py", line 227, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\migrations\migration.py", line 126, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\migrations\operations\models.py", line 269, in database_forwards
schema_editor.delete_model(model)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\backends\sqlite3\schema.py", line 311, in delete_model
super().delete_model(model)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\backends\base\schema.py", line 363, in delete_model
self.execute(self.sql_delete_table % {
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\backends\base\schema.py", line 145, in execute
cursor.execute(sql, params)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\backends\utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\ashwi\Documents\GitHub\AMCH\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 423, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: Recruiter_jobs
(env) PS C:\Users\ashwi\Documents\GitHub\AMCH\AMCH_Recruiter>
what's the error cause here? I have even tried to delete this model but still no changes... it gives the same error.
please suggest any solution for it.

Djonog: storing an ArrayField gives an ambiguous error 'django.db.utils.DatabaseError'

I'm trying to store an ArrayField in a Django model called User, I'm using MongoDB and Djongo.
I managed to do it with one model called Pair, I can store a list of Pairs and store that list in a User model using ArrayField which was fairly simple, I just followed this example from Djongo's official doc
Now I'm trying to store another list but for some reason, it just keeps giving me a huge TraceBack (90 lines) with an ambiguous error: 'django.db.utils.DatabaseError'
here's my user model:
class User(AbstractBaseUser):
email = models.EmailField(verbose_name='email address', max_length=127, unique=True)
first_name = models.CharField(verbose_name='First Name', max_length=30, blank=True)
last_name = models.CharField(verbose_name='Last Name', max_length=30, blank=True)
is_active = models.BooleanField(default=True, verbose_name='Active')
is_admin = models.BooleanField(default=False, verbose_name='Admin')
pairs = models.ArrayField (
model_container=Pair,
null=True
)
conversations = models.ArrayField(
model_container=Conversation,
null=True
)
again, the pairs attribute is working just fine but the conversation is not
The Pair model
class Pair(models.Model):
name = models.CharField(max_length=16)
purchase_price = models.DecimalField(verbose_name='Purchase price', max_digits=20, decimal_places=6)
class Meta:
ordering = ['name']
abstract=True
The Conversation model
class Conversation(models.Model):
handle = models.CharField(max_length=255)
class Meta:
abstract = True
and this is the traceback:
Operations to perform:
Apply all migrations: accounts, admin, auth, contenttypes, sessions, tracker
Running migrations:
Not implemented alter command for SQL ALTER TABLE "accounts_user" ADD COLUMN "conversations" array NULL
Applying accounts.0003_user_conversations...Traceback (most recent call last):
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/djongo/cursor.py", line 51, in execute
self.result = Query(
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 783, in __init__
self._query = self.parse()
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 875, in parse
raise e
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 856, in parse
return handler(self, statement)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 888, in _alter
query = AlterQuery(self.db, self.connection_properties, sm, self._params)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 425, in __init__
super().__init__(*args)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 84, in __init__
super().__init__(*args)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 62, in __init__
self.parse()
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 435, in parse
self._add(statement)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 598, in _add
raise SQLDecodeError(err_key=tok.value,
djongo.exceptions.SQLDecodeError:
Keyword: array
Sub SQL: ALTER TABLE "accounts_user" ADD COLUMN "conversations" array NULL
FAILED SQL: ('ALTER TABLE "accounts_user" ADD COLUMN "conversations" array NULL',)
Params: ([],)
Version: 1.3.4
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/djongo/cursor.py", line 59, in execute
raise db_exe from e
djongo.database.DatabaseError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 231, in handle
post_migrate_state = executor.migrate(
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/migrations/operations/fields.py", line 110, in database_forwards
schema_editor.add_field(
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 480, in add_field
self.execute(sql, params)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 142, in execute
cursor.execute(sql, params)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/akram/Desktop/cointracker/.venv/lib/python3.8/site-packages/djongo/cursor.py", line 59, in execute
raise db_exe from e
django.db.utils.DatabaseError
Note: when I run python manage.py migrate, migrations are created with no problem, but when I apply them, I get the above error
Problem solved!
turned out that there's a problem with Djonogo specifically in this file djongo/sql2mongo/query.py
this question has already been answered in this comment on the djongo Github page

I am not migrate in python django

Operations to perform:
Apply all migrations: admin, auth, contenttypes, main, sessions
Running migrations:
Applying main.0004_auto_20210301_2201...Traceback (most recent call last):
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\base.py", line 411, in execute
return Database.Cursor.execute(self, query)
sqlite3.OperationalError: no such function: JSON_VALID
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 371, in execute
output = self.handle(*args, **options)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\migrate.py", line 243, in handle
post_migrate_state = executor.migrate(
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 227, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\operations\fields.py", line 236, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 138, in alter_field
super().alter_field(model, old_field, new_field, strict=strict)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\schema.py", line 571, in alter_field
self._alter_field(model, old_field, new_field, old_type, new_type,
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 360, in _alter_field
self._remake_table(model, alter_field=(old_field, new_field))
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 280, in _remake_table
self.create_model(new_model)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\schema.py", line 324, in create_model
self.execute(sql, params or None)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\schema.py", line 142, in execute
cursor.execute(sql, params)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "C:\Users\devia\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\base.py", line 411, in execute
return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: no such function: JSON_VALID
here is the traceback. plz someone help me with this no able to migrate.
first i create a progres json field in table and did not work so i drop it. now everything is not working plz help with his
Models.py is blank
and everything is blank but not able to migrate
here is the traceback. plz someone help me with this no able to migrate.
first i create a progres json field in table and did not work so i drop it. now everything is not working plz help with his
Models.py is blank
and everything is blank but not able to migrate

Django migrating foreign keys django.db.utils.OperationalError: (1005, "Can't create table 'asp052mysqlpy.#sql-6ac_56' (errno: 150)") error

I'm trying to migrate a simple foreign key relation for a model in Django, but this results in a very strange and unsolvable error.
Error:
python manage.py migrate team
Operations to perform:
Apply all migrations: team
Running migrations:
Applying team.0001_initial... OK
Applying team.0002_auto_20191127_1643...Traceback (most recent call last):
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
return self.cursor.execute(query, args)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\cursors.py", line 255, in execute
self.errorhandler(self, exc, value)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\cursors.py", line 252, in execute
res = self._query(query)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\cursors.py", line 378, in _query
db.query(q)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\connections.py", line 280, in query
_mysql.connection.query(self, query)
_mysql_exceptions.OperationalError: (1005, "Can't create table 'asp052mysqlpy.#sql-6ac_56' (errno: 150)")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\core\management\base.py", line 353, in execute
output = self.handle(*args, **options)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
fake_initial=fake_initial,
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\migrations\operations\fields.py", line 216, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\base\schema.py", line 523, in alter_field
old_db_params, new_db_params, strict)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\base\schema.py", line 744, in _alter_field
self.execute(self._create_fk_sql(model, new_field, "_fk_%(to_table)s_%(to_column)s"))
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\base\schema.py", line 133, in execute
cursor.execute(sql, params)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
return self.cursor.execute(query, args)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\cursors.py", line 255, in execute
self.errorhandler(self, exc, value)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\cursors.py", line 252, in execute
res = self._query(query)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\cursors.py", line 378, in _query
db.query(q)
File "C:\Users\Mitch\Desktop\teamwork\teamworkapp\lib\site-packages\MySQLdb\connections.py", line 280, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1005, "Can't create table 'asp052mysqlpy.#sql-6ac_56' (errno: 150)")
Models:
class Tmteams(models.Model):
teamid = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
class Meta:
db_table = 'tmteams'
class Tmteamsusers(models.Model):
teamid = models.ForeignKey(Tmteams, on_delete=models.CASCADE, db_column='teamid')
userid = models.ForeignKey(User, on_delete=models.CASCADE, db_column='userid')
class Meta:
db_table = 'tmteamsusers'
unique_together = (('userid', 'teamid'),)
Migration file that errors:
class Migration(migrations.Migration):
dependencies = [
('team', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='tmteamsusers',
name='teamid',
field=models.ForeignKey(db_column='teamid', on_delete=django.db.models.deletion.CASCADE, to='team.Tmteams'),
),
migrations.AlterField(
model_name='tmteamsusers',
name='userid',
field=models.ForeignKey(db_column='userid', on_delete=django.db.models.deletion.CASCADE, to='users.User'),
),
]
I'm using the following modules and MySQL version:
Django 2.1.5
mysqlclient 1.3.14
MySQl 5.1.7.3 Community edition
Anyone that can help me out?
I've found and solved the problem. The table I'm referencing to (allmodusers) was still using the MyISAM database engine. I've changed the database engine of this table to InnoDB after reading the following article: https://kinsta.com/knowledgebase/convert-myisam-to-innodb/.

Categories

Resources