title: How to specify a text column's value as a string union?
body: <p>I have a struct <code>Document</code>:</p>
  <pre><code>type Document struct {
      ID               entity.EntityID
      Type             string
      ContentType      files.MIMEType
      URL              string
      UploadedByUserID entity.EntityID
      CreatedAt        time.Time
  }
  
  type MIMEType string
  
  const (
      MIMETypeJPG MIMEType = &quot;image/jpeg&quot;
      MIMETypePDF MIMEType = &quot;application/pdf&quot;
      MIMETypePNG MIMEType = &quot;image/png&quot;
      MIMETypeTXT MIMEType = &quot;text/plain&quot;
  )
  </code></pre>
  <p>It maps to a <code>documents</code> table where the <code>ContentType</code> column is of type <code>varchar(1024)</code>:</p>
  <pre><code>create table documents(
      id bigint not null default nextval('documents_id_seq') PRIMARY KEY,
      url varchar(1024) not null,
      type varchar(1024) not null,
      content_type varchar(1024) not null,
      uploaded_by_user_id bigint,
      created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP not null
  );
  </code></pre>
  <p><code>Create(&amp;d)</code> where <code>d</code> is a <code>Document</code> instance gives me an error:</p>
  <pre><code>[2.530ms] [rows:1] INSERT INTO &quot;documents&quot; (&quot;type&quot;,&quot;content_type&quot;,&quot;url&quot;,&quot;uploaded_by_user_id&quot;,&quot;created_at&quot;) VALUES ('other_freight','image/png','https://lateralline-documents-dev.s3.us-west-2.amazonaws.com/doc-other_freight-2021_08_25__11_15_13_379569000.png','253608954016301056','2021-08-25 11:15:13.82') RETURNING &quot;id&quot;
  interface conversion: interface {} is files.MIMEType, not string
  </code></pre>
  <p>I want to tell gorm that when I read and write the <code>documents.content_type</code> field it is not just an arbitrary string, it should be a <code>files.MIMEType</code> value. Is there a way to do this? I've seen this functionality in other ORMs.</p>