Monday, February 22, 2016

Re: key specification without a key length

Thanks Mike,

I'm using models and I made the changes like you suggested but I'm still getting the same error....

id = models.CharField(max_length=99, primary_key=True)


python manage.py makemigrations talk

Migrations for 'talk':

  0008_auto_20160222_1925.py:

    - Remove field ids from userconfig

    - Add field id to userconfig

    - Alter field id on steps


python manage.py migrate talk

Operations to perform:

  Apply all migrations: talk

Running migrations:

  Rendering model states... DONE

  Applying talk.0003_steps...Traceback (most recent call last):

  File "manage.py", line 10, in <module>

    execute_from_command_line(sys.argv)

  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line

    utility.execute()

  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 345, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv

    self.execute(*args, **cmd_options)

  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 399, in execute

    output = self.handle(*args, **options)

  File "/Library/Python/2.7/site-packages/django/core/management/commands/migrate.py", line 200, in handle

    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)

  File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 92, in migrate

    self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)

  File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards

    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)

  File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 198, in apply_migration

    state = migration.apply(state, schema_editor)

  File "/Library/Python/2.7/site-packages/django/db/migrations/migration.py", line 123, in apply

    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)

  File "/Library/Python/2.7/site-packages/django/db/migrations/operations/models.py", line 59, in database_forwards

    schema_editor.create_model(model)

  File "/Library/Python/2.7/site-packages/django/db/backends/base/schema.py", line 284, in create_model

    self.execute(sql, params or None)

  File "/Library/Python/2.7/site-packages/django/db/backends/base/schema.py", line 110, in execute

    cursor.execute(sql, params)

  File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 79, in execute

    return super(CursorDebugWrapper, self).execute(sql, params)

  File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 64, in execute

    return self.cursor.execute(sql, params)

  File "/Library/Python/2.7/site-packages/django/db/utils.py", line 95, in __exit__

    six.reraise(dj_exc_type, dj_exc_value, traceback)

  File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 62, in execute

    return self.cursor.execute(sql)

  File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 112, in execute

    return self.cursor.execute(query, args)

  File "/Library/Python/2.7/site-packages/MySQLdb/cursors.py", line 205, in execute

    self.errorhandler(self, exc, value)

  File "/Library/Python/2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler

    raise errorclass, errorvalue

django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'id' used in key specification without a key length")



On Friday, February 19, 2016 at 1:30:46 PM UTC-8, Sammi Singh wrote:
Hi,

I'm new to Django and facing this error "django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'id' used in key specification without a key length")"

Here is my code:

class Steps(models.Model):

    author = models.ForeignKey(User)

#    id = models.TextField(primary_key=True)

    id = models.CharField(primary_key=True, max_length = 32)

    text = models.TextField()

    status = models.TextField()

    step_id = models.TextField(null=True)

    release_id = models.TextField(null=True)

    region = models.TextField(null=True)

    # Time is a rhinocerous

    updated = models.DateTimeField(auto_now=True)

    created = models.DateTimeField(auto_now_add=True)


class UserConfig(models.Model):

    author = models.ForeignKey(User)

#    id = models.TextField(primary_key=True)

    id = models.CharField(primary_key=True, max_length = 32)

    co_range = models.TextField()

    tu_range = models.TextField()

    st_range = models.TextField()

    de_host = models.TextField()

    in_host1 = models.TextField()

    in_host2 = models.TextField()

    in_host3 = models.TextField()

    co_host = models.TextField()

    vp_name = models.TextField()


    # Time is a rhinocerous

    updated = models.DateTimeField(auto_now=True)

    created = models.DateTimeField(auto_now_add=True)


Any help would be appreciated......


Regards

Sammi

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7dd0d105-be6b-419d-bf50-f1eb26ef0a27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment