On 23/02/2016 6:37 AM, Sammi Singh wrote:
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)*

That was a stab in the dark trying to indicate to you that a text field is inappropriate as a key field.

I also indicated that it is unusual to even use a char field as primary key. You would want to be certain such a path is necessary. It is also highly unusual to want a primary key to carry specific business data such as might be your intention.

Before expending effort on fixing the problem*, can you explain why you want to control the primary key yourself instead of giving that task to Django's built-in primary key?

* The last line of the traceback indicates the migration failed then naturally rolled the transaction back and left your database with an unchanged text (blob) field as primary key. Why it failed I don't know but there is probably an easier solution.

Mike



/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+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto: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
<https://groups.google.com/d/msgid/django-users/7dd0d105-be6b-419d-bf50-f1eb26ef0a27%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscr...@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/56CB7525.2040502%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

Reply via email to