Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get django-activity-stream database tables installed

Using django-south, is it possible to setup a table only to the last, most recent configuration without applying all the preceeding migrations?

We are interested in using a 3rd party tool (django-activity-stream) but are having difficulties running all the migrations, for somewhat unknown reasons (possibly MySQL issues regarding a particular field) - specifically migration 003, which raises an error

_mysql_exceptions.OperationalError: (1170, "BLOB/TEXT column 'object_id' used in key specification without a key length") " I strongly suspect that avoiding the migrations and going straight to the current schema will avoid this.

The ability to migrate backwards is not required, only the need to get us to the current schema right now, and I don't want to hack the package to deal with this. I can't seem to establish the commands, or whether this is even possible?

config:

south 0.7.6, django 1.3.x, mysql 5.5.x, django-activity-stream 0.4.4

like image 749
Aitch Avatar asked Aug 16 '12 08:08

Aitch


2 Answers

This error is coming because of the way actstream handles its Generic Foreign keys. The problem arises with MySql because it sees text-fields without any length specified.

This error can be fixed by making the migration 0003 a no-op.

Change the following things in migrations 0003_text_field_ids, 0004_char_field_ids in the actstream:

0003_text_field_ids.py:

  1. remove everything in def forwards(self, orm), def backwards(self, orm) and just write pass in both.
  2. Change TextField to PositiveIntegerField.

0004_char_field_ids.py:

  1. In def backwards(self, orm), change TextField to PositiveIntegerField in all db.altercolumns().

This makes migration 0003 a noop using pass for forwards and backwards and makes the model's definition use PositiveIntegerFields for the Generic Foreign keys, so they're kept in the same state as migration 0001 left them. Doing this, migration 0004 can pick up from the PositiveIntegerFields to varChars. Then the fix changes migration 0004 so the backward migration changes to PositiveIntegerFields instead of TextFields.

This should hopefully fix your issue.

like image 190
Suhaas Avatar answered Oct 15 '22 23:10

Suhaas


I dont think the problem is caused by migrations, even syncdb will give you the same result.

The error is coming because MySQL can index only the first N chars of a BLOB or TEXT column. So you must be having a field/column type of TEXT or BLOB that you are trying to make as primary key or index.

With full BLOB or TEXT without the length value, MySQL will be unable to guarantee the uniqueness of the column as it’s of variable and dynamic size. So, when using BLOB or TEXT types as index, the value of N must be supplied so that MySQL can determine the key length.

Try to fix this problem and then try to apply migration, it should work nicely. and Yes you can apply any migrations and skipping the older ones but I'll recommend not to do this as thats not how south is supposed to be used.

Hope I made things little bit clear.

like image 33
Rohit Avatar answered Oct 16 '22 01:10

Rohit