FAILED_TO_CREATE_USER - when trying to signup user and password #1511

Closed
opened 2026-03-13 08:44:25 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @AceCodePt on GitHub (Jul 17, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

import { Pool } from "pg";
import logger from "@logger";
import { env } from "node:process";

const pool = new Pool({
  host: env.DATABASE_HOST,
  port: env.DATABASE_PORT,
  database: env.DATABASE_NAME,
  user: env.DATABASE_USER,
  password: env.DATABASE_PASSWORD,
  ssl: env.DATABASE_SSL === "require",
  max: 20,
  idleTimeoutMillis: 30000,
  connectionTimeoutMillis: 2000,
});

Ran the following schema to my neon db

create table "user" ("id" text not null primary key, "name" text not null, "email" text not null unique, "emailVerified" boolean not null, "image" text, "createdAt" timestamp not null, "updatedAt" timestamp not null);

create table "session" ("id" text not null primary key, "expiresAt" timestamp not null, "token" text not null unique, "createdAt" timestamp not null, "updatedAt" timestamp not null, "ipAddress" text, "userAgent" text, "userId" text not null references "user" ("id"));

create table "account" ("id" text not null primary key, "accountId" text not null, "providerId" text not null, "userId" text not null references "user" ("id"), "accessToken" text, "refreshToken" text, "idToken" text, "accessTokenExpiresAt" timestamp, "refreshTokenExpiresAt" timestamp, "scope" text, "password" text, "createdAt" timestamp not null, "updatedAt" timestamp not null);

create table "verification" ("id" text not null primary key, "identifier" text not null, "value" text not null, "expiresAt" timestamp not null, "createdAt" timestamp, "updatedAt" timestamp);

I don't think it matters but I run it against AstroJS with Neon as my DB

Current vs. Expected behavior

Expect Should just sign up the user.

The result is:
{"code":"FAILED_TO_CREATE_USER","message":"Failed to create user","details":{"length":303,"name":"error","severity":"ERROR","code":"23502","detail":"Failing row contains (sf7h5SO7TQ6EeV6k6QdMBSD73sQL8keN, null, ace@ace.com, f, null, 2025-07-17 08:22:26.854, 2025-07-17 08:22:26.854).","schema":"public","table":"user","column":"name","file":"execMain.c","line":"1982","routine":"ExecConstraints"}}

What version of Better Auth are you using?

11.2.12

Provide environment information

- OS Linux ubuntu
- Framework AstroJS
- DB postgres (with Neon)

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

export const auth = betterAuth({
  emailAndPassword: { enabled: true, autoSignIn: true },
  rateLimit: { enabled: import.meta.env.PROD },
  database: pool,
  logger: {
    log(level, message, ...args) {
      logger[level](message, args);
    },
  },
  socialProviders: {
    google: {
      clientId: env.GOOGLE_CLIENT_ID as string,
      clientSecret: env.GOOGLE_CLIENT_SECRET as string,
    },
    apple: {
      clientId: env.APPLE_CLIENT_ID as string,
      clientSecret: env.APPLE_CLIENT_SECRET as string,
    },
  },
})

Additional context

It is probably an issue with how the schema was created and how it is actually saved in the DB.

Originally created by @AceCodePt on GitHub (Jul 17, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ```ts import { Pool } from "pg"; import logger from "@logger"; import { env } from "node:process"; const pool = new Pool({ host: env.DATABASE_HOST, port: env.DATABASE_PORT, database: env.DATABASE_NAME, user: env.DATABASE_USER, password: env.DATABASE_PASSWORD, ssl: env.DATABASE_SSL === "require", max: 20, idleTimeoutMillis: 30000, connectionTimeoutMillis: 2000, }); ``` Ran the following schema to my neon db ```sql create table "user" ("id" text not null primary key, "name" text not null, "email" text not null unique, "emailVerified" boolean not null, "image" text, "createdAt" timestamp not null, "updatedAt" timestamp not null); create table "session" ("id" text not null primary key, "expiresAt" timestamp not null, "token" text not null unique, "createdAt" timestamp not null, "updatedAt" timestamp not null, "ipAddress" text, "userAgent" text, "userId" text not null references "user" ("id")); create table "account" ("id" text not null primary key, "accountId" text not null, "providerId" text not null, "userId" text not null references "user" ("id"), "accessToken" text, "refreshToken" text, "idToken" text, "accessTokenExpiresAt" timestamp, "refreshTokenExpiresAt" timestamp, "scope" text, "password" text, "createdAt" timestamp not null, "updatedAt" timestamp not null); create table "verification" ("id" text not null primary key, "identifier" text not null, "value" text not null, "expiresAt" timestamp not null, "createdAt" timestamp, "updatedAt" timestamp); ``` I don't think it matters but I run it against AstroJS with Neon as my DB ### Current vs. Expected behavior Expect Should just sign up the user. The result is: {"code":"FAILED_TO_CREATE_USER","message":"Failed to create user","details":{"length":303,"name":"error","severity":"ERROR","code":"23502","detail":"Failing row contains (sf7h5SO7TQ6EeV6k6QdMBSD73sQL8keN, null, ace@ace.com, f, null, 2025-07-17 08:22:26.854, 2025-07-17 08:22:26.854).","schema":"public","table":"user","column":"name","file":"execMain.c","line":"1982","routine":"ExecConstraints"}} ### What version of Better Auth are you using? 11.2.12 ### Provide environment information ```bash - OS Linux ubuntu - Framework AstroJS - DB postgres (with Neon) ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const auth = betterAuth({ emailAndPassword: { enabled: true, autoSignIn: true }, rateLimit: { enabled: import.meta.env.PROD }, database: pool, logger: { log(level, message, ...args) { logger[level](message, args); }, }, socialProviders: { google: { clientId: env.GOOGLE_CLIENT_ID as string, clientSecret: env.GOOGLE_CLIENT_SECRET as string, }, apple: { clientId: env.APPLE_CLIENT_ID as string, clientSecret: env.APPLE_CLIENT_SECRET as string, }, }, }) ``` ### Additional context It is probably an issue with how the schema was created and how it is actually saved in the DB.
Author
Owner

@dosubot[bot] commented on GitHub (Jul 17, 2025):

The error happens because the Better Auth signup flow requires a non-null name field, but your signup request doesn't provide one, and your schema marks name as NOT NULL. This is a known issue: the CLI-generated schema and the signup endpoint are out of sync—signup doesn't send a name, but the DB expects it, so you get a NOT NULL constraint violation (source, source).

You have two options:

  1. Change your schema to make name nullable if you don't want to collect it:
    alter table "user" alter column "name" drop not null;
    
  2. Auto-fill the name field with a placeholder during signup if you don't collect it from users. For example, in your signup handler, add:
    const name = req.body.name || "Anonymous";
    // pass `name` to the signup/createUser call
    

This mismatch is fixed in upcoming releases, so upgrading to the latest beta may resolve it without manual workarounds (source). If you want to keep the NOT NULL constraint, make sure your signup payload always includes a name value.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jul 17, 2025): <!-- Answer --> The error happens because the Better Auth signup flow requires a non-null `name` field, but your signup request doesn't provide one, and your schema marks `name` as NOT NULL. This is a known issue: the CLI-generated schema and the signup endpoint are out of sync—signup doesn't send a name, but the DB expects it, so you get a NOT NULL constraint violation ([source](https://github.com/better-auth/better-auth/issues/3394), [source](https://github.com/better-auth/better-auth/discussions/3222)). You have two options: 1. Change your schema to make `name` nullable if you don't want to collect it: ```sql alter table "user" alter column "name" drop not null; ``` 2. Auto-fill the `name` field with a placeholder during signup if you don't collect it from users. For example, in your signup handler, add: ```ts const name = req.body.name || "Anonymous"; // pass `name` to the signup/createUser call ``` This mismatch is fixed in upcoming releases, so upgrading to the latest beta may resolve it without manual workarounds ([source](https://github.com/better-auth/better-auth/issues/3394)). If you want to keep the NOT NULL constraint, make sure your signup payload always includes a `name` value. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/bba2869e-cfaa-42b7-95ab-d8b587723d89?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/bba2869e-cfaa-42b7-95ab-d8b587723d89?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/bba2869e-cfaa-42b7-95ab-d8b587723d89?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/bba2869e-cfaa-42b7-95ab-d8b587723d89?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/bba2869e-cfaa-42b7-95ab-d8b587723d89?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/bba2869e-cfaa-42b7-95ab-d8b587723d89?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/bba2869e-cfaa-42b7-95ab-d8b587723d89?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3421)
Author
Owner

@AceCodePt commented on GitHub (Jul 17, 2025):

@dosu It generates the name as not null. Does it need to be migrated or generated after I've made the change?

@AceCodePt commented on GitHub (Jul 17, 2025): @dosu It generates the name as not null. Does it need to be migrated or generated after I've made the change?
Author
Owner

@dosubot[bot] commented on GitHub (Jul 17, 2025):

Yes, after you change the schema to make the name column nullable, you need to run a migration (like ALTER TABLE) to update the actual database structure. Just regenerating the schema or code isn’t enough—the migration is what applies the change to your live database. There’s no Better Auth-specific migration tool, so you can use standard tools (like manual SQL or something like Alembic) for this step. Once the migration runs, the change will take effect and you shouldn’t see the NOT NULL error anymore.
Reference

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jul 17, 2025): <!-- Answer --> Yes, after you change the schema to make the name column nullable, you need to run a migration (like ALTER TABLE) to update the actual database structure. Just regenerating the schema or code isn’t enough—the migration is what applies the change to your live database. There’s no Better Auth-specific migration tool, so you can use standard tools (like manual SQL or something like Alembic) for this step. Once the migration runs, the change will take effect and you shouldn’t see the NOT NULL error anymore. [Reference](https://github.com/better-auth/better-auth/issues/3394) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/902b93bf-2b87-4241-a780-50fd12c60ec2?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/902b93bf-2b87-4241-a780-50fd12c60ec2?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/902b93bf-2b87-4241-a780-50fd12c60ec2?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/902b93bf-2b87-4241-a780-50fd12c60ec2?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/902b93bf-2b87-4241-a780-50fd12c60ec2?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/902b93bf-2b87-4241-a780-50fd12c60ec2?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/902b93bf-2b87-4241-a780-50fd12c60ec2?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3421)
Author
Owner

@AceCodePt commented on GitHub (Jul 17, 2025):

@dosu It for some reason also regenerate the name back without the default '' (which is what I've decided to do)
Any reason for that?

@AceCodePt commented on GitHub (Jul 17, 2025): @dosu It for some reason also regenerate the name back without the default '' (which is what I've decided to do) Any reason for that?
Author
Owner

@dosubot[bot] commented on GitHub (Jul 17, 2025):

That's because the schema generator in Better Auth always reflects its internal model and overwrites manual changes—so any default value you add to the name column (like default '') gets removed on regeneration. There's currently no config option to persist a default value for name; you'll need to reapply your manual change after each regeneration, or upgrade to a newer (beta) release once the fix for this is published (details).

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jul 17, 2025): <!-- Answer --> That's because the schema generator in Better Auth always reflects its internal model and overwrites manual changes—so any default value you add to the name column (like default '') gets removed on regeneration. There's currently no config option to persist a default value for name; you'll need to reapply your manual change after each regeneration, or upgrade to a newer (beta) release once the fix for this is published ([details](https://github.com/better-auth/better-auth/issues/2674)). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/5807b76a-3a32-4447-9dc3-47f9ba50320d?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/5807b76a-3a32-4447-9dc3-47f9ba50320d?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/5807b76a-3a32-4447-9dc3-47f9ba50320d?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/5807b76a-3a32-4447-9dc3-47f9ba50320d?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/5807b76a-3a32-4447-9dc3-47f9ba50320d?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/5807b76a-3a32-4447-9dc3-47f9ba50320d?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/5807b76a-3a32-4447-9dc3-47f9ba50320d?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3421)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1511