influitive / apartment

Database multi-tenancy for Rack (and Rails) applications
2.67k stars 463 forks source link

Options for tenant DB creation #551

Open pdurkim opened 6 years ago

pdurkim commented 6 years ago

Steps to reproduce

MySQL DB character set = utfb8mb4 and collate = utf8mb4_bin

Expected behavior

Create the tenant in DB

Actual behavior

Apartment::Tenant.create(tenant_name) results in following error: "Error while creating tenant development_tenant_name: Mysql2::Error: COLLATION 'utf8mb4_bin' is not valid for CHARACTER SET 'utf8': CREATE DATABASE 'development_tenant_name' DEFAULT CHARACTER SET 'utf8' COLLATE 'utf8mb4_bin'"

System configuration

mikecmpbll commented 6 years ago

can you be more precise in your description of the problem and how it relates to apartment? your steps to reproduce are somewhat lacking.

MySQL DB character set = utfb8mb4 and collate = utf8mb4_bin

how are these configured? the error you quote seems to suggest a character set of 'utf8'. is apartment not passing this through correctly?

mdi commented 4 years ago

I'm seeing the same issue, e.g. having this in config/database.yml:

  adapter: mysql2
  encoding: utf8mb4
  collation: utf8mb4_unicode_ci

Produces this error when attempting to create a tenant:

Mysql2::Error: COLLATION 'utf8mb4_unicode_ci' is not valid for CHARACTER SET 'utf8': CREATE DATABASE `foo` DEFAULT CHARACTER SET `utf8` COLLATE `utf8mb4_unicode_ci
mdi commented 4 years ago

This is fixed by providing charset: utf8mb4 in config/database.yml.