I am coding an app in Expo using sqlite database. On iOS, everything is OK, but on Android it's not working.
LOG Error [Error: Error code : no such table: cars]
import React, { useEffect } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import * as SQLite from 'expo-sqlite';
import * as Notifications from 'expo-notifications';
import HomeScreen from './Screens/HomeScreen';
import AddCarScreen from './Screens/AddCarScreen';
import CarDetailScreen from './Screens/CarDetailScreen';
import EditCarScreen from './Screens/EditCarScreen.js';
// Funkce pro inicializaci databáze
const initializeDatabase = () => {
const db = SQLite.openDatabase('MyCars.db');
db.transaction((tx) => {
tx.executeSql(
`CREATE TABLE IF NOT EXISTS cars (
id INTEGER PRIMARY KEY AUTOINCREMENT,
brand TEXT,
model TEXT,
licensePlate TEXT,
vin TEXT,
technicalInspectionDate TEXT,
serviceInspectionDate TEXT,
highwayStampValidityDate TEXT,
techInspNotif1 TEXT,
techInspNotif2 TEXT,
servInspNotif1 TEXT,
servInspNotif2 TEXT,
highwayStampNotif1 TEXT,
highwayStampNotif2 TEXT
);`,
[],
() => console.log('Table cars created successfully'),
(error) => console.log('Error creating table: ' + error.message)
);
});
};
const Stack = createNativeStackNavigator();
const App = () => {
useEffect(() => {
initializeDatabase();
registerForPushNotificationsAsync();
}, []);
// Funkce pro požádání o zapnutí notifikací
async function registerForPushNotificationsAsync() {
const { status } = await Notifications.requestPermissionsAsync();
if (status !== 'granted') {
alert('Omlouváme se, nemáme povolení zasílat vám push notifikace.');
return;
}
// Pokud chcete získat a využít token, doplňte kód zde
}
return (
<NavigationContainer>
<Stack.Navigator initialRouteName='Home'>
<Stack.Screen name='Home' component={HomeScreen} />
<Stack.Screen name='AddCar' component={AddCarScreen} />
<Stack.Screen name='CarDetail' component={CarDetailScreen} />
<Stack.Screen name='EditCar' component={EditCarScreen} />
</Stack.Navigator>
</NavigationContainer>
);
};
export default App;
I tried using the emulator in Android Studio, the Expo Go app, and I even installed apk on physical device.