I’m trying to import data as a new collection with a reference field, however every time I do this, the imported reference field has “Reference Broken” error. I can’t understand why.
Here’s what I’m trying to do:
Import a list of schools and school holiday dates. Holiday dates are set by region. If a school belongs to that region those holiday dates should be returned in a table.
Table 1: List of schools - 1000 records, each individual school has a region field
Table 2: List of dates by region, 150 regions. The region in this table is the primary key.
Region field in the school and the region table are an exact match
I want the region fields to be linked as a reference field but every time I try to upload these the reference field seems to fail.
What am I doing wrong?
Hi Euan,
references in Wix Code work by referencing the ID field in collection being referenced. ID field is different from what we call “Primary Field”.
Lets try to model those two tables.
We have a school, which say looks like this
| School Name: Text | Region: Reference to Region |
| Wix Middle School | region1 |
| Wix High School | region2 |
and Region table which then could look like this
| ID | Region Name: Text | Date: Date |
| region1 | Nice Region Name | 2017-01-15 |
| region2 | Somehwere in the mountains | 2017-01-30 |
Notice, that I am putting the value of ID field to the Reference field in School table (both in italic). As references are always by ID, at this point it does not matter which field is selected as Primary Field. What Primary Field controls, is which field is used to represent the item (Region in your case) in Content Manager. So, if Region Name is selected as Primary Field, you will see the Region Name when looking at School table.
I hope this helps. Let me know if you need any further assistance. And have fun Wix Coding!
Hi Giedrius
Thanks for the reply. I’m not sure what I’m missing but it doesn’t seem to be working for me.
I’ve recreated your two tables, I import the Region table first, renaming the ID column.

When I import the School table, I change the region ID to a Reference field. The upload checker page looks fine as if this will import.
When the import is complete I get a blank column where I would expect to see the region.
Thanks
Euan
It seems you are doing everything right! The trick here, is that the Primary Field (display field for the element) is still the Title in your Region table. So it appears as if references are not populated, although they probably are.
You can go to Region table, click on Region Name column and select Set As Primary Field. This will make Region Name appear in all places where regions are referenced. So you should be able to see it in your Region column in School table.
Let me know if this helps!
The reference to “ID” field, is the unique database ID given to every entry. This is HIDDEN by default. If you click on “Visible Fields” you’ll see that ID is unchecked. If you enable it, you’ll see a gray background column appear, THAT is the true ID field, and that is what you need to use to reference instead of whatever text you’re currently using.

Copy that long ID, and put it into a new column in the CSV you’re importing. In my case, I just called it ID_Ref:
When I import, instead of using AcctNum as a reference field (similar to your region), I used ID_Ref as the reference field.
You’ll know you’ve done it properly because you’ll see the ID_ref value, change to the Primary field value of the referenced database. (the first column in my first screenshot)