Table 'restaurant-service.food_menu' doesn't exist

I need to get all information about restaurant, but when Im doing a request, I have an error Table ‘restaurant-service.food_menu’ doesn’t exist, so I just don’t know how to fix it, but my post request is working excellent here is my database

Domain

Restaurant
@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "Restaurant")
public class Restaurant {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "RESTAURANT_ID")
    private Long id;

    private String restaurantName;

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "restaurant")
    private List<FoodMenu> menu;

    @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinColumn(name = "ADDRESS_ID")
    private Address address;

}

FoodMenu
@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "FoodMenu")
public class FoodMenu {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "FOOD_MENU_ID")
    private Long id;

    private String foodName;

    private String foodDescription;

    private BigDecimal foodPrice;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "RESTAURANT_ID")
    private Restaurant restaurant;

}

Service
@Service
@Transactional
public class RestaurantService {
@Autowired
private RestaurantRepository restaurantRepository;

    public void saveRestaurant(Restaurant restaurant){
         restaurantRepository.save(restaurant);
    }

    public List<Restaurant> allRestaurants(){
        return restaurantRepository.findAll();
    }
}

Controller
@RestController
public class RestaurantController {

    @Autowired
    private RestaurantService restaurantService;

    @PostMapping("/create")
    public void createUploadRestaurant(@RequestBody Restaurant restaurant){
      restaurantService.saveRestaurant(restaurant);
    }

    @GetMapping("/showAllRestaurants")
    public List<Restaurant> showRestaurants(){
        return restaurantService.allRestaurants();
    }
}

>Solution :

The name you defined doesn’t match what you defined.

'restaurant-service.food_menu'  != @Table(name = "FoodMenu")
@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "FoodMenu")
public class FoodMenu {
. . . .

Leave a Reply