Python SQLDecodeError(err_key=tok.value,djongo.exceptions.SQLDecodeError
我正在Django和mongoDB一起做一个项目。我的应用程序名为Python SQLDecodeError(err_key=tok.value,djongo.exceptions.SQLDecodeError,python,django,mongodb,Python,Django,Mongodb,我正在Django和mongoDB一起做一个项目。我的应用程序名为app mymodels.py: class myCustomeUser(AbstractUser): #id = models.AutoField(primary_key=True) username = models.CharField(max_length=20, unique="True", blank=False) password = models.CharField(max
app
mymodels.py
:
class myCustomeUser(AbstractUser):
#id = models.AutoField(primary_key=True)
username = models.CharField(max_length=20, unique="True", blank=False)
password = models.CharField(max_length=20, blank=False)
is_Employee = models.BooleanField(default=False)
is_Inspector = models.BooleanField(default=False)
is_Industry = models.BooleanField(default=False)
is_Admin = models.BooleanField(default=False)
def __str__(self):
return self.username
class Industry(models.Model):
user = models.OneToOneField(myCustomeUser, on_delete=models.CASCADE, primary_key=True, related_name='industry_releted_user')
name = models.CharField(max_length=200, blank=True)
owner = models.CharField(max_length=200, blank=True)
license = models.IntegerField(null=True, unique=True)
industry_extrafield = models.TextField(blank=True)
def __str__(self):
return self.name
class Employee(models.Model):
user = models.ForeignKey(myCustomeUser, null=True, blank=True, on_delete=models.CASCADE)
industry = models.ForeignKey(Industry, null=True, blank=True, on_delete=models.CASCADE)
i_id = models.IntegerField(unique=True)
name = models.CharField(max_length=200, blank=False, null=True)
gmail = models.EmailField(null=True, blank=False, unique=True)
rank = models.CharField(max_length=20, blank=False, null=True)
employee_varified = models.BooleanField(default=False, blank=True, null=True)
def __str__(self):
return self.name
class Inspector(models.Model):
user = models.ForeignKey(myCustomeUser, on_delete=models.CASCADE, related_name='inspector_releted_user')
name = models.CharField(max_length=200, blank=False, null=True)
gmail = models.EmailField(null=True, blank=False, unique=True)
nationalid = models.IntegerField(null=True, blank=False, unique=True)
inspector_extrafield = models.TextField(blank=True)
def __str__(self):
return self.name
class Admin(models.Model):
user = models.ForeignKey(myCustomeUser, on_delete=models.CASCADE, related_name='admin_releted_user')
name = models.CharField(max_length=200, blank=False, null=True)
gmail = models.EmailField(null=True, blank=False, unique=True)
admin_extrafield = models.TextField(blank=True)
def __str__(self):
return self.name
class PrevJob(models.Model):
employee = models.ForeignKey(Employee, null=True, blank=True, on_delete=models.CASCADE)
industry = models.ForeignKey(Industry, null=True, blank=True, on_delete=models.CASCADE)
i_id = models.IntegerField(unique=True)
#name = models.CharField(max_length=200, blank=False, null=True)
rank = models.CharField(max_length=20, blank=False, null=True)
def __str__(self):
return self.employee.name
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'ProjectSurokkhaBetaDB_5',
}
}
在settings.py
中:
class myCustomeUser(AbstractUser):
#id = models.AutoField(primary_key=True)
username = models.CharField(max_length=20, unique="True", blank=False)
password = models.CharField(max_length=20, blank=False)
is_Employee = models.BooleanField(default=False)
is_Inspector = models.BooleanField(default=False)
is_Industry = models.BooleanField(default=False)
is_Admin = models.BooleanField(default=False)
def __str__(self):
return self.username
class Industry(models.Model):
user = models.OneToOneField(myCustomeUser, on_delete=models.CASCADE, primary_key=True, related_name='industry_releted_user')
name = models.CharField(max_length=200, blank=True)
owner = models.CharField(max_length=200, blank=True)
license = models.IntegerField(null=True, unique=True)
industry_extrafield = models.TextField(blank=True)
def __str__(self):
return self.name
class Employee(models.Model):
user = models.ForeignKey(myCustomeUser, null=True, blank=True, on_delete=models.CASCADE)
industry = models.ForeignKey(Industry, null=True, blank=True, on_delete=models.CASCADE)
i_id = models.IntegerField(unique=True)
name = models.CharField(max_length=200, blank=False, null=True)
gmail = models.EmailField(null=True, blank=False, unique=True)
rank = models.CharField(max_length=20, blank=False, null=True)
employee_varified = models.BooleanField(default=False, blank=True, null=True)
def __str__(self):
return self.name
class Inspector(models.Model):
user = models.ForeignKey(myCustomeUser, on_delete=models.CASCADE, related_name='inspector_releted_user')
name = models.CharField(max_length=200, blank=False, null=True)
gmail = models.EmailField(null=True, blank=False, unique=True)
nationalid = models.IntegerField(null=True, blank=False, unique=True)
inspector_extrafield = models.TextField(blank=True)
def __str__(self):
return self.name
class Admin(models.Model):
user = models.ForeignKey(myCustomeUser, on_delete=models.CASCADE, related_name='admin_releted_user')
name = models.CharField(max_length=200, blank=False, null=True)
gmail = models.EmailField(null=True, blank=False, unique=True)
admin_extrafield = models.TextField(blank=True)
def __str__(self):
return self.name
class PrevJob(models.Model):
employee = models.ForeignKey(Employee, null=True, blank=True, on_delete=models.CASCADE)
industry = models.ForeignKey(Industry, null=True, blank=True, on_delete=models.CASCADE)
i_id = models.IntegerField(unique=True)
#name = models.CharField(max_length=200, blank=False, null=True)
rank = models.CharField(max_length=20, blank=False, null=True)
def __str__(self):
return self.employee.name
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'ProjectSurokkhaBetaDB_5',
}
}
今天早上,我删除了完整的数据库(并创建了一个全新的数据库),删除了app\migrations
中的所有文件(除了\uuu init\uuuuuuuuu.py
)。然后运行makemigrations
,然后运行migrate
。但在运行migrate
命令后,终端显示以下错误:
Operations to perform:
Apply all migrations: admin, app, auth, contenttypes, sessions
Running migrations:
This version of djongo does not support "NULL, NOT NULL column validation check" fully. Visit https://www.patreon.com/nesdis
Applying contenttypes.0001_initial...This version of djongo does not support "schema validation using CONSTRAINT" fully. Visit https://www.patreon.com/nesdis
OK
Applying contenttypes.0002_remove_content_type_name...This version of djongo does not support "COLUMN DROP NOT NULL " fully. Visit https://www.patreon.com/nesdis
This version of djongo does not support "DROP CASCADE" fully. Visit https://www.patreon.com/nesdis
OK
Applying auth.0001_initial...This version of djongo does not support "schema validation using KEY" fully. Visit
https://www.patreon.com/nesdis
This version of djongo does not support "schema validation using REFERENCES" fully. Visit https://www.patreon.com/nesdis
OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying auth.0010_alter_group_name_max_length... OK
Applying auth.0011_update_proxy_permissions... OK
Not implemented alter command for SQL ALTER TABLE "app_employee" ADD COLUMN "industry_id" int NULL
Applying app.0001_initial...Traceback (most recent call last):
File "G:\Python\lib\site-packages\djongo\cursor.py", line 51, in execute
self.result = Query(
File "G:\Python\lib\site-packages\djongo\sql2mongo\query.py", line 783, in __init__
self._query = self.parse()
File "G:\Python\lib\site-packages\djongo\sql2mongo\query.py", line 875, in parse
raise e
File "G:\Python\lib\site-packages\djongo\sql2mongo\query.py", line 856, in parse
return handler(self, statement)
File "G:\Python\lib\site-packages\djongo\sql2mongo\query.py", line 888, in _alter
query = AlterQuery(self.db, self.connection_properties, sm, self._params)
File "G:\Python\lib\site-packages\djongo\sql2mongo\query.py", line 425, in __init__
super().__init__(*args)
File "G:\Python\lib\site-packages\djongo\sql2mongo\query.py", line 84, in __init__
super().__init__(*args)
File "G:\Python\lib\site-packages\djongo\sql2mongo\query.py", line 62, in __init__
self.parse()
File "G:\Python\lib\site-packages\djongo\sql2mongo\query.py", line 435, in parse
self._add(statement)
File "G:\Python\lib\site-packages\djongo\sql2mongo\query.py", line 598, in _add
raise SQLDecodeError(err_key=tok.value,
djongo.exceptions.SQLDecodeError:
Keyword: int
Sub SQL: ALTER TABLE "app_employee" ADD COLUMN "industry_id" int NULL
FAILED SQL: ('ALTER TABLE "app_employee" ADD COLUMN "industry_id" int NULL',)
Params: ([],)
Version: 1.3.3
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "G:\Python\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "G:\Python\lib\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 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "G:\Python\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "G:\Python\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "G:\Python\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "G:\Python\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "G:\Python\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "G:\Python\lib\site-packages\django\core\management\commands\migrate.py", line 231, in handle
post_migrate_state = executor.migrate(
File "G:\Python\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 "G:\Python\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 "G:\Python\lib\site-packages\django\db\migrations\executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "G:\Python\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 "G:\Python\lib\site-packages\django\db\migrations\operations\fields.py", line 110, in database_forwards
schema_editor.add_field(
File "G:\Python\lib\site-packages\django\db\backends\base\schema.py", line 480, in add_field
self.execute(sql, params)
File "G:\Python\lib\site-packages\django\db\backends\base\schema.py", line 142, in execute
cursor.execute(sql, params)
File "G:\Python\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "G:\Python\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 "G:\Python\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "G:\Python\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "G:\Python\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "G:\Python\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "G:\Python\lib\site-packages\djongo\cursor.py", line 59, in execute
raise db_exe from e
django.db.utils.DatabaseError
我以前从未遇到过这种奇怪的问题。我如何解决这个问题?你在迁移手册中添加了SQL吗Lyno,我没有添加那种东西你使用的djongo版本是什么,sqlparse
djongo
版本是1.3.3,sqlparse
版本可能是0.2.4你在迁移手册中添加了SQL吗Lyno,我没有t添加这类内容您使用的djongo版本是什么?sqlparsedjongo
版本是1.3.3,sqlparse版本可能是0.2.4