16
Views
3
Comments
Foreign Key - Could not change the type of attribute
Application Type
Reactive
Service Studio Version
11.9.1 (Build 33435)

Hi, 

I am new to OutSystems, and I want to create an app with an excel file. I have two tables, one for employees and another for the department. 

In the employee's table, there is the DepartmentName attribute, which has values. In the Department table,  there is the DepartmentName attribute also with the same values. 


After uploading my data into OutSystems Service, it creates an ID attribute automatically with a longinteger type for both tables. 

I changed the data type for the DepartmentName attribute from "text" to "Department Identifier" in the employee table (FK). However, after publishing the app, this error Appears, "Could not change the type of attribute 'Departmentname' of entity 'Employee' from 'Text' to 'Long Integer'. There are values that cannot be converted to 'Long Integer'. Consider creating a new attribute and logic to migrate existing values." 


What I want to do is :

having a drop list for the department name when the user enters a new employee, and I want the user to be able to add a new department to the department register page.


I hope I describe my problem well. 


Thank you so much.

Rank: #70

Hi AlJoharah,


When you publish a module, OutSystems will try to make the necessary changes to the database automatically but sometimes due to constraints like that it is not possible.

In order to publish, you can add a new field of the type Department Identifier (e.g. DepartmentId) and remove the attribute DepatrmentName. With that, you should be able to publish.


Just take into account that the records you had already on that table will have the new field with its default null value.


Hope it helps.


Regards,
João

Hello AlJoharah


Another way to approach will be changing data in your excel file and upload in OS. You can first replace all Deptname text to corresponding integer value in Employee excel. Then upload it first, and upload second file(dept) and immediately change the data type of Identifier to integer(from Long Int), and make FK relationship.


Sanjay

Hi,

Your Excel Should be like this. In department table No need to create column for department Id. Outsystems will auto generate it.

Department

DeptName

Employee

Name, DeptId

ABC       1

PQR       2

XYZ         2

POL      1

Once you bootstrap your excel files Expand your Employee Entity => Right Click on DeptId column and change it's Data Type to Department Identifier. Now check it.