Error writing to postgreSQL hosted on Heroku

Feature(s) impacted

I am not able to perform database writes in a production environment.

Observed behavior

The instance does not get written to the DB.

The GUI shows a red error when creating an instance of any model of my Django project that says “Unexpected Error”.

Expected behavior

An instance of a model should be created using the creation forms provided by Forest Admin.

Failure Logs

The console shows the following error message: “Ember Data Request POST https://gateway.forestadmin.tech//forest/users_user returned a 500\nPayload”

Context

  • Project name: Vinos.com
  • Team name: Personal
  • Environment name: Default (Production)
  • Agent (forest package) name & version: Cloud Hosted
  • Database type: postgreSQL
  • Recent changes made on your end if any: Setup the admin panel

Hey @0xdesdenova, and welcome to our community :wave:

I can definitely see an error on our end regarding this call

null value in column \"id\" of relation \"users_user\" violates not-null constraint

This error should be displayed as a toastr on your end as well, so let me know if that’s not the case.

If you are using Django, you can also give a try to our self hosted/advanced setup integration, as we are also directly compatible with this framework.

Let me know if that helps.

1 Like

Thank you very much for replying so fast.

It works perfectly when running locally (although I’m using SQLite). I imagine the error is specifically in PostgreSQL.

From the trace you shared (which does not display on my developer console), the UUID is not automatically generated when saving instances to PostgreSQL from Forest Admin.

Have you encountered this behavior previously?

Could you share a DDL for this specific postgres table?
(Just to check that the database structure mention the autogenerated UUID on postgres)

From the trace you shared (which does not display on my developer console)

I’ll give this a shot on my end to check, but you should see a toastr displaying this kind of message.

the UUID is not automatically generated when saving instances to PostgreSQL from Forest Admin.
Have you encountered this behavior previously?

Is the id field in read-only mode when using the creation form ?

In the meantime, I’ll try to reproduce the issue on my end.

1 Like

Yes. All relevant fields have been marked as read only.

Sure, here is the DDL:

CREATE TABLE "users_user" ("id" uuid NOT NULL PRIMARY KEY, "email" varchar(254) NOT NULL UNIQUE, "referral_code" uuid NOT NULL, "phone" varchar(25) NULL, "first_name" varchar(50) NULL, "last_name" varchar(50) NULL, "gender" varchar(1) NULL, "birth_date" date NULL, "recurrente_id" varchar(50) NULL, "active" boolean NOT NULL, "timestamp" timestamp with time zone NOT NULL);

And here is my Django model:

import uuid

class User(models.Model):
    GENDER_CHOICES = [
        ('M', 'Male'),
        ('F', 'Female')
    ]
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    email = models.EmailField(unique=True)
    referral_code = models.UUIDField(default=uuid.uuid4)
    phone = models.CharField(max_length=50, null=True, blank=True)
    first_name = models.CharField(max_length=50, null=True, blank=True)
    last_name = models.CharField(max_length=50, null=True, blank=True)
    gender = models.CharField(
        max_length=1, choices=GENDER_CHOICES, null=True, blank=True)
    birth_date = models.DateField(null=True, blank=True)
    recurrente_id = models.CharField(max_length=50, null=True, blank=True)
    active = models.BooleanField(default=True)
    timestamp = models.DateTimeField(auto_now_add=True)
1 Like

Good news! The problem seems to be with the one click configuration wizard. I performed an in app setup, then deployed that, and the GUI works like a charm.

One thing of note, for Django projects, configuring an environment variable will be necessary to finish setup.

DJANGO_SETTINGS_MODULE=<your_project_name>.settings

Or at least, this is one of the ways in which you are able to properly configure your settings when using Forest Admin.

1 Like

@0xdesdenova

Good news indeed!

According to the DDL you shared, your id primary key doesn’t have a default value declared in SQL.
Looking at you model, it seems like the default UUID value is computed from Django via default=uuid.uuid4.

Our one click deploy directly plugs on top of your database and not from your Django app - thus it cannot generate a default value for your primary key.

You could define the default value in SQL directly (The syntax is DBS dependant though). Doing would allow to use the one click deploy with your database, while still being able to add new records with a default id :slight_smile:

Let me know if that helps

1 Like