Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
PostgreSQL, remove varchar limit. #14579
There is no reason for the PG adapter to have a default limit of 255 on :string
added a commit
this pull request
Apr 4, 2014
referenced this pull request
Apr 6, 2014
Thanks for creating a test for #13435. I've got to know Oracle enhanced adapter also needs #13435 support.
(5.6ms) CREATE TABLE "ACCOUNTS" ("ID" NUMBER(38) NOT NULL PRIMARY KEY, "FIRM_ID" NUMBER(38), "FIRM_NAME" VARCHAR2, "CREDIT_LIMIT" NUMBER(38)) OCIError: ORA-00906: missing left parenthesis: CREATE TABLE "ACCOUNTS" ("ID" NUMBER(38) NOT NULL PRIMARY KEY, "FIRM_ID" NUMBER(38), "FIRM_NAME" VARCHAR2, "CREDIT_LIMIT" NUMBER(38))
If I understand the reason mysql/mysql2 does not support this yet is MySQL varchar datatype also needs length specified.
(1.7ms) CREATE TABLE `accounts` (`id` int(11) auto_increment PRIMARY KEY, `firm_id` int(11), `firm_name` varchar, `credit_limit` int(11)) ENGINE=InnoDB Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' `credit_limit` int(11)) ENGINE=InnoDB' at line 1: CREATE TABLE `accounts` (`id` int(11) auto_increment PRIMARY KEY, `firm_id` int(11), `firm_name` varchar, `credit_limit` int(11)) ENGINE=InnoDB
I'm thinking about how to implement this as follows but I'm not sure if it is a good idea or not.
@yahonda as far as I know MySQL doesn't need it but there are / were concerns when it's not specified. The reason why it's not supported at the moment is a bug
If Oracle requires a limit that code should first live in the Oracle adapter. None of the core adapters do require the
Hope that helps. Let me know if you have further questions / suggestions and thanks for the heads up!
I have a similar problem to @lukewendling. We have two dev boxes both running Rails 4.2, but as soon as I create a migration and it gets run on the other box, it adds limits to all the string fields in the schema file. When a migration is created on the other dev box, it does not do this.
@constantm it means that databases in these boxes are become different: one does have limits and another does not (for example someone have run migrations from scratch on another box after upgrade).
You should stick to the configuration you have in production. Dump database schema from production database, restore it on one of dev boxes, run
If you do not want to have limits on string columns, create migration that will remove them:
class RemoveLimitFromStringColumns < ActiveRecord::Migration def up # repeat for all your tables and all your columns execute 'ALTER TABLE "your_table" ALTER COLUMN "your_column" TYPE character varying;' end def down # repeat for all your tables and all your columns execute 'ALTER TABLE "your_table" ALTER COLUMN "your_column" TYPE character varying(255);' end end
If you do not have production yet, just drop database and rerun all migrations from scratch.
Anyway, current behaviour is correct, and previous Rails versions were buggy by creating columns with implicit limit and not displaying it in