Hi I'm doing my own server using python-virtualenv, django, nginx, uwsgi
.
Django database is mysql. when i migrate django project on virtualenv, always
django.db.utils.OperationalError:
(1170, "BLOB/TEXT column 'credential_id_data' used
in key specification without a key length")
this error came out. i don't know why this error happened. when I google, someone said in model.py, TextField is not good, use Charfield. but my code is charfield... i don't know why this error happend.
Here is the model.py
from django.contrib.auth.models import(BaseUserManager, AbstractBaseUser, PermissionsMixin)
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from django.utils.translation import ugettext_lazy as _
class UserManager(BaseUserManager):
use_in_migrations = True
def create_user(self, username, userid, company, companycode, password=None):
if not username:
raise ValueError(_('Users must have an name!'))
user = self.model(
username=username,
userid = userid,
company= company,
companycode = companycode,
)
user.set_password(companycode) #usrid를 암호화
user.save()
return user
def create_superuser(self, username, userid, company, companycode, password):
user = self.create_user(
username=username,
userid = userid,
company = company,
companycode = companycode,
password=password,
)
user.set_password(password)
user.is_superuser = True
user.is_active = True
user.save()
return user
class User(AbstractBaseUser, PermissionsMixin):
username = models.CharField(max_length=50, unique=True, verbose_name="이름")
userid = models.CharField(max_length=40, unique=True, verbose_name="아이디")
company = models.CharField(max_length=100, verbose_name="회사")
companycode = models.CharField(max_length=100, verbose_name="회사코드")
created_date = models.DateTimeField(auto_now_add=True, verbose_name="생성날짜")
is_admin = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
class Meta:
db_table = 'user'
objects = UserManager()
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['userid', 'company', 'companycode']
def __str__(self):
return self.username
def get_full_name(self):
return self.username
def get_short_name(self):
return self.username
@property
def is_staff(self):
"Is the user a member of staff?"
# Simplest possible answer: All superusers are staff
return self.is_superuser
get_full_name.short_description = _('Full name')
and this is error
Applying django_fido.0010_credential_id_not_null...Traceback (most recent call last):
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 74, in execute
return self.cursor.execute(query, args)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.OperationalError: (1170, "BLOB/TEXT column 'credential_id_data' used in key specification without a key length")
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 "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 231, in handle
post_migrate_state = executor.migrate(
File "/Users/junbeomkwak/Desktop/fido_virtual/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 "/Users/junbeomkwak/Desktop/fido_virtual/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 "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "/Users/junbeomkwak/Desktop/fido_virtual/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 "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/db/migrations/operations/fields.py", line 249, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 566, in alter_field
self._alter_field(model, old_field, new_field, old_type, new_type,
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 747, in _alter_field
self.execute(self._create_unique_sql(model, [new_field.column]))
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 142, in execute
cursor.execute(sql, params)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/Users/junbeomkwak/Desktop/fido_virtual/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 "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 74, in execute
return self.cursor.execute(query, args)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/Users/junbeomkwak/Desktop/fido_virtual/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'credential_id_data' used in key specification without a key length")