Add a database to your project
Every project can use the built-in backend (Cloud), which includes a managed PostgreSQL database. Describe the data your app needs in the project chat, and Lovable creates the tables and their structure for you. For example, tell Lovable:View tables and data
The Database view lists your project’s tables with an approximate row count for each. Click a table to browse and edit its records. Tables populate as soon as your app saves information. The list also includes any database views your app uses. A database view shows data drawn from one or more tables, and you can read it but not edit it.Edit records
Open a table to view and edit its records. Double-click a value to edit it in place. You can also:- Filter: add one or more column filters. Available operators depend on the column type, for example equals or contains for text, greater than or less than for numbers, and before or after for dates.
- Add row: opens a form based on the table’s structure. The database fills in some columns itself, such as IDs and timestamps, so the form leaves those out.
- Edit row: opens the full row for editing. Editing a row works only in tables with a single primary key, the column that identifies each row.
- Delete: select rows and delete them. The button names how many rows you selected, and Lovable asks you to confirm. Deleting rows cannot be undone.
- Export CSV: download the table’s records as a CSV file. The file contains every row that matches your current filters, not only the page you see. For a copy of the whole database, see Export your database.
- Refresh: reload the table after your app writes new data. The view does not update live.
Read your form submissions
Ask Lovable for a form that visitors use to reach you, such as a contact, booking, or quote form. Lovable creates a table for it and saves each submission as a row. Lovable tells you the table’s name in the project chat. To read the submissions, go to More → Database and open that table. Lovable sets the table’s access rules so that visitors can submit the form but cannot read, change, or delete a submission. Anyone with edit access to the project can read the whole table. To get each submission by email as well, tell Lovable which address to send it to. See Can Lovable email me when someone submits a form?. You can have submissions go to a service you already use instead of a table, such as a customer relationship management (CRM) system. Name the destination when you ask for the form, or ask Lovable to change it later. For a form that delivers elsewhere, Lovable does not create a table. Lovable offers to store a copy as well, so a failed delivery does not lose the submission.Find the tools around your database
In the Database view, select Manage to open the tools around your database:- Jobs: scheduled background tasks in your app. See Jobs.
- SQL editor: run your own queries against the database. See Run SQL queries.
- Edge functions: the server-side code your app runs. See Edge functions.
- Backups: the daily backups you can restore. See Back up, restore, and export your app’s database.
- Policies: the rules that decide which rows each user can see or change. See Row level security (RLS) policies.
- Settings: the database itself, rather than the data in it.
Check where your database is hosted
To see the region your database runs in, go to More → Database, select Manage, then Settings. The Database location row shows that region and the PostgreSQL version your database runs. The row names the region the way the hosting provider does, for example Europe (Frankfurt) for a database in Europe. The region is set when the database is created and cannot be changed afterwards. Existing projects cannot be moved between regions. To choose the region for a project before you create its database, see Choose where your project’s data is stored.Run SQL queries
For direct database access, open the SQL editor: in the Database view, select Manage, then SQL editor. Write your query, then click Run or press ⌘/Ctrl + Enter. The editor autocompletes table and column names from your database. Results appear in a table below the query. If a query fails, the error message appears in its place. Click Clear to empty the editor. If a query contains a destructive statement such asDELETE, DROP, TRUNCATE, ALTER, or UPDATE, Lovable asks you to confirm before running it.
When you run SQL in the SQL editor, you change your database directly. Lovable does not save that SQL as a migration file or add it to the record of migrations in your database. Your migration files therefore do not include changes you make in the SQL editor.
How Lovable changes your database structure
When you ask for a new table, column, or access rule in the project chat, Lovable makes the change. Lovable also updates the type definitions in your app’s code, so the code matches the database. Lovable records each change as a migration file in your project’s code, underdrizzle/migrations/. A migration file is an SQL file that describes one change to the database structure. Your code therefore carries the full history of how your database was built.
Lovable uses Drizzle, an open-source tool for database migrations, to create and apply migration files. Some projects use an earlier setup, where Lovable writes each migration file under supabase/migrations/ instead. In projects that moved to Drizzle, Lovable leaves the earlier files under supabase/migrations/.
Lovable refuses changes that could break your published app:
- Dropping or renaming a table or column
- Changing a column’s type
- Adding a required column without a default value
drizzle folder, including drizzle/schema.ts, and the drizzle.config.ts file in your project’s code, so leave them as they are.
How migrations run
Each time Lovable changes your database structure, it applies your migration files, the SQL files that record each change, in a migration run. Lovable applies migrations on a database connection that can change your database structure and create access policies onstorage.objects, the table behind your storage files. Your app’s own code uses different connections.
This section covers projects whose migration files are under drizzle/migrations/. On the earlier setup, with files under supabase/migrations/, Lovable applies only the change you asked for. If someone adds a migration file to supabase/migrations/ through a synced Git repository, Lovable applies the file only when you ask.
In projects with files under drizzle/migrations/, three things about how Lovable runs migrations can be unexpected:
- Lovable can also apply earlier changes in your project’s code that it has not applied yet, not only the change you asked for.
- When one statement fails, Lovable applies none of the changes in the run.
- When Lovable reports a timeout, Lovable can still apply the change afterwards.
drizzle/migrations/meta/_journal.json, is the list Drizzle uses to find migrations to apply. A migration file’s journal entry must have a date after the last migration Lovable applied.
A developer who creates a migration with Drizzle’s command-line tool, drizzle-kit, gets the journal entry automatically. If someone copies an SQL file into drizzle/migrations/ without a journal entry, Lovable does not apply the file.
Lovable applies all pending migrations together, in one run. If one statement fails, Lovable discards every change from that run and applies nothing, so your database stays as it was before the run.
A timeout is different from a failed statement. A timeout means Lovable stopped waiting for the result, and Lovable can still apply the change afterwards. Before you ask for the same change again, check whether Lovable applied it, so Lovable does not apply it twice. For example, ask Lovable in the project chat:
Supported PostgreSQL extensions
A PostgreSQL extension adds a capability to your database, such as scheduled jobs or vector search. Your project’s database supports a fixed set of extensions:plpgsql, pg_graphql, pg_stat_statements, pgcrypto, uuid-ossp, and pgsodium preinstalled.
To enable a supported extension, ask Lovable in the project chat or run the statement in the SQL editor:
CREATE EXTENSION statement for any other extension before it runs. The refusal applies when you ask in the project chat, run SQL in the SQL editor, or send SQL through the Lovable API or the Lovable MCP server.
The SQL editor shows an error that lists the supported extensions. The API returns a 403 response with the error type unsupported_extension and a message that lists the supported extensions.
When you ask for a feature that would need an unsupported extension, Lovable builds it with plain SQL instead. For example:
- Instead of
citext, Lovable uses atextcolumn with a unique index onlower(column). - Instead of
hstore, Lovable uses ajsonbcolumn. - Instead of
http, Lovable makes the request withpg_net.
FAQ
Can I install a PostgreSQL extension that isn't on the supported list?
Can I install a PostgreSQL extension that isn't on the supported list?
CREATE EXTENSION for any other extension in the project chat, the SQL editor, and the API. When a feature would need an unsupported extension, Lovable builds it with plain SQL instead, and extensions already installed keep working. See Supported PostgreSQL extensions.Does a failed statement undo the whole migration?
Does a failed statement undo the whole migration?
- Write your SQL without
BEGIN,COMMIT, orROLLBACK. Lovable rejects migrations that contain them. - A few statements cannot run inside a transaction, such as
CREATE INDEX CONCURRENTLY. - On the earlier setup, with files under
supabase/migrations/, contact support before you rely on a full rollback.
Does the migration history match my migration files?
Does the migration history match my migration files?
drizzle/migrations/ keep the record in a Drizzle table, where each row stores a SHA-256 hash of the file as it was when it ran. A file you change later no longer matches its hash. Projects on the earlier setup keep the record in the Supabase migrations table, which stores a version and a name but no hash.How do I record a migration I already ran in the SQL editor?
How do I record a migration I already ran in the SQL editor?
Can I undo a migration without restoring a backup?
Can I undo a migration without restoring a backup?
Is there a size limit for a migration?
Is there a size limit for a migration?
Does pushing to my repository apply migrations?
Does pushing to my repository apply migrations?
Can Lovable apply only the migration I approved?
Can Lovable apply only the migration I approved?
Does a timeout mean my migration was not applied?
Does a timeout mean my migration was not applied?
Can two migrations run at the same time?
Can two migrations run at the same time?
Are failed migrations retried?
Are failed migrations retried?
Does the SQL editor run my statements in one transaction?
Does the SQL editor run my statements in one transaction?
What are the drizzle files in my project's code?
What are the drizzle files in my project's code?
drizzle/migrations/ folder contains one SQL file per change, and drizzle.config.ts and drizzle/schema.ts are configuration files Drizzle needs. Leave them as they are. See How Lovable changes your database structure.