Skip to content

MySQL bigint auto_increment primary_key is not dumped correct in db/schema.rb #19232

@ChristianStancu

Description

@ChristianStancu

Hi,

I have tried to create a table with an bigint as primary_key and auto_increment for a MySQL database.

My Migration was

class CreateTests < ActiveRecord::Migration
  def change
    create_table :tests, id: false do |t|
      t.integer :id, limit: 8, auto_increment: true, primary_key: true
      t.string :name
    end
  end
end

Auto_increment and primary_key have been ignored.

CREATE TABLE `tests` (
  `id` bigint(20) DEFAULT NULL,
  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

The db/schema.rb looked like

create_table "tests", id: false, force: :cascade do |t|
  t.integer "id",   limit: 8
  t.string  "name", limit: 255
end

A second try

class CreateTests < ActiveRecord::Migration
  def change
    create_table :tests do |t|
      t.string :name
    end

   change_column :tests, :id, :integer, limit: 8, auto_increment: true, primary_key: true
  end
end

The MySQL-Table was build correct

CREATE TABLE `tests` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

But the db/schema.rb looked like

create_table "tests", force: :cascade do |t|
  t.string "name", limit: 255
end

And after a rake db:reset resets the column was changed back to integer instead of bigint.

Best
Chris

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions