Blog

How to Create Data Tables, Columns and Relations by Importing CSV Files

by on April 1, 2020

Backendless can create tables when you store object hierarchies from a client application. Also, we described how to manually create data tables using Backendless Console.

Finally, there is one more approach that makes table creation as simple as it gets. This approach is by uploading a file that contains a schema definition for every table. The schema definition may include data types for all columns, including the ones for relations.

As a part of our quest to build a restaurant to-go order app, we created all the tables in my Backendless backend. We used the schema export feature which generated a ZIP file with the schema definitions for all the tables used by the app.

The ZIP archive includes a CSV file for every table:

The structure of each CSV file is rather simple. In this case, it contains just the names of the columns and the corresponding data types.

Additionally, they may contain data objects too, but that is described in a separate post. For example, the following are the contents of Location.csv: and Restaurant.csv: As you can see, every column definition in the files contains the column name and the corresponding data type. Using this approach, we can create all the tables, with columns and relations. The Backendless documentation describes the import file format for defining column names and their types. Follow the instructions below to import the file and create all the tables for the Restaurant app in your backend:

  1. Download the ZIP file which contains the definition for all tables from https://backendless.com/docs/samples/restaurant-app-schema.zip.
  2. Login to Backendless Console, select an app (it is recommended to create a new app for this) and click the Manage icon.
  3. Select the Import menu item.
  4. Click the Backendless app browse button and browse to the ZIP file from step 1 above.
    Import Zip File
  5. Once the file is selected, Backendless immediately starts processing it and creating data tables. As soon as the process is finished, an email is delivered to the application developer with the status of the import. The email for the restaurant-app-schema.zip file should contain the following status:
    1	03:55:44  IMPORT_DATA  Importing Started.
    2	03:55:44  IMPORT_DATA  Start import table: Menu
    3	03:55:44  IMPORT_DATA  Table 'Menu' was imported at 0 seconds
    4	03:55:44  IMPORT_DATA  Finish import table: Menu
    5	03:55:44  IMPORT_DATA  Start import table: Users
    6	03:55:44  IMPORT_DATA  Table 'Users' was imported at 0 seconds
    7	03:55:44  IMPORT_DATA  Finish import table: Users
    8	03:55:44  IMPORT_DATA  Start import table: Order
    9	03:55:44  IMPORT_DATA  Table 'Order' was imported at 0 seconds
    10	03:55:44  IMPORT_DATA  Finish import table: Order
    11	03:55:45  IMPORT_DATA  Start import table: Restaurant
    12	03:55:45  IMPORT_DATA  Table 'Restaurant' was imported at 0 seconds
    13	03:55:45  IMPORT_DATA  Finish import table: Restaurant
    14	03:55:45  IMPORT_DATA  Start import table: Location
    15	03:55:45  IMPORT_DATA  Table 'Location' was imported at 0 seconds
    16	03:55:45  IMPORT_DATA  Finish import table: Location
    17	03:55:45  IMPORT_DATA  Start import table: MenuItem
    18	03:55:45  IMPORT_DATA  Table 'MenuItem' was imported at 0 seconds
    19	03:55:45  IMPORT_DATA  Finish import table: MenuItem
    20	03:55:45  IMPORT_DATA  Importing Finished.
  6. To confirm that all the tables, columns and relations have been created, click the Data icon. You should see the following tables in the list:
    Empty Restaurant Table

2 Comments

The link to download zip file here is broken: https://backendless.com/documentation/samples/restaurant-app-schema.zip does not exist

Hi Egil,
Thanks for pointing out the error! The link has been replaced so the zip file is available again.

Leave a Reply