Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually. #21

Closed
phodal opened this issue Sep 22, 2015 · 5 comments

Comments

@phodal
Copy link
Owner

phodal commented Sep 22, 2015

as title

@phodal
Copy link
Owner Author

phodal commented Sep 22, 2015

MySQL

'ALTER TABLE django_content_type DROP COLUMN name'

@phodal
Copy link
Owner Author

phodal commented Sep 22, 2015

There's no ALTER COLUMN in sqlite.

I believe your only option is to:

  1. Rename the table to a temporary name
  2. Create a new table without the NOT NULL constraint
  3. Copy the content of the old table to the new one
  4. Remove the old table

Say you have a table and need to rename "colb" to "col_b":

First you rename the old table:

ALTER TABLE orig_table_name RENAME TO tmp_table_name;

Then create the new table, based on the old table but with the updated column name:

CREATE TABLE orig_table_name (
  col_a INT
, col_b INT
);

Then copy the contents across from the original table.

INSERT INTO orig_table_name(col_a, col_b)
SELECT col_a, colb
FROM tmp_table_name;

Lastly, drop the old table.

DROP TABLE tmp_table_name;

Wrapping all this in a BEGIN TRANSACTION; and COMMIT; is also probably a good idea.

@phodal
Copy link
Owner Author

phodal commented Sep 22, 2015

CREATE TABLE "django_content_type" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "app_label" varchar(100) NOT NULL, "model" varchar(100) NOT NULL, UNIQUE ("app_label", "model"))

@phodal
Copy link
Owner Author

phodal commented Sep 22, 2015

ALTER TABLE django_content_type RENAME TO content_type_old;

CREATE TABLE "django_content_type" (
"id" integer NOT NULL PRIMARY KEY,
"app_label" varchar(100) NOT NULL,
"model" varchar(100) NOT NULL,
UNIQUE ("app_label", "model")
);

INSERT INTO django_content_type(id, app_label,model)
SELECT id, app_label,model
FROM content_type_old;

DROP TABLE content_type_old;

@phodal
Copy link
Owner Author

phodal commented Sep 22, 2015

@phodal phodal closed this as completed Sep 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant